Habe das ganze überarbeitet und die Fehler welche ich im Betrieb gefunden habe beseitigt Beitrag aktuallisiert:
Mit etwas Basteln habe ich eine Zeitschaltuhr mit Wochenprogramm gebastelt. Hier kann für jeden Wochentag 2 Schaltzeitpunkte eingestellt werden (AN/AUS), auch ist es möglich einzelne Wochentage auszuschalten.
das Ganze Widget sieht so aus:
Screenshot 2021-04-16 140159.jpg
der code dazu ist etwas komplizierter
Code: Alles auswählen
uid: TimeControllerWeek
tags: []
props:
parameters:
- context: item
description: An item to control
label: Item
name: item
required: false
type: TEXT
parameterGroups: []
timestamp: Apr 22, 2021, 10:17:23 AM
component: f7-card
slots:
default:
- component: f7-row
config:
class:
- justify-content-center
- align-items-center
- text-align-center
slots:
default:
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: " "
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Mo:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Di:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Mi:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Do:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Fr:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Sa:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "So:"
- component: f7-row
config:
class:
- justify-content-center
- align-items-center
- text-align-center
style:
margin-top: 20px
margin-buttom: 20px
slots:
default:
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Ein:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[0].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: moEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[1].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: diEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[2].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: miEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[3].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: doEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[4].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: frEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[5].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: saEin
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[6].split(',')[0])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: soEin
bgColor: white
textColor: black
- component: f7-row
config:
class:
- justify-content-center
- align-items-center
- text-align-center
style:
margin-top: 20px
margin-buttom: 20px
slots:
default:
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Aus:"
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[0].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: moAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[1].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: diAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[2].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: miAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[3].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: doAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[4].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: frAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[5].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: saAus
bgColor: white
textColor: black
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: oh-input
config:
type: time
defaultValue: =(items[props.item].state.split(';')[6].split(',')[1])
validate: true
step: 60
min: 00:00
max: 23:59
required: true
variable: soAus
bgColor: white
textColor: black
- component: f7-row
config:
class:
- justify-content-center
- align-items-center
- text-align-center
style:
margin-top: 20px
margin-buttom: 20px
slots:
default:
- component: f7-col
config:
style:
margin-right: 10px
slots:
default:
- component: Label
config:
text: "Aktiv:"
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: moAktiv
actionVariableValue: "0"
disabled: "=(vars.moAktiv) ? (vars.moAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2]) === '0') "
textColor: "=(vars.moAktiv) ? ( (vars.moAktiv === '0') ? 'green' : 'red') : (((items[props.item].state.split(';')[0].split(',')[2]) === '0') ? 'green' : 'red')"
active: "=(vars.moAktiv) ? (vars.moAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2]) === '0') "
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: moAktiv
actionVariableValue: 1
disabled: "=(vars.moAktiv) ? (vars.moAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2]) === '1') "
textColor: "=(vars.moAktiv) ? ( (vars.moAktiv === 1) ? 'green' : 'red') : (((items[props.item].state.split(';')[0].split(',')[2]) === '1') ? 'green' : 'red')"
active: "=(vars.moAktiv) ? (vars.moAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2]) === '1') "
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: diAktiv
actionVariableValue: "0"
active: "=(vars.diAktiv) ? (vars.diAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[1].split(',')[2]) === '0') : false) "
disabled: "=(vars.diAktiv) ? (vars.diAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[1].split(',')[2]) === '0') : false) "
textColor: "=(vars.diAktiv) ? ( (vars.diAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[1].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: diAktiv
actionVariableValue: 1
active: "=(vars.diAktiv) ? (vars.diAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[1].split(',')[2]) === '1') : false) "
disabled: "=(vars.diAktiv) ? (vars.diAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[1].split(',')[2]) === '1') : false) "
textColor: "=(vars.diAktiv) ? ( (vars.diAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[1].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: miAktiv
actionVariableValue: "0"
active: "=(vars.miAktiv) ? (vars.miAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[2].split(',')[2]) === '0') : false) "
disabled: "=(vars.miAktiv) ? (vars.miAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[2].split(',')[2]) === '0') : false) "
textColor: "=(vars.miAktiv) ? ( (vars.miAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[2].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: miAktiv
actionVariableValue: 1
active: "=(vars.miAktiv) ? (vars.miAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[2].split(',')[2]) === '1') : false) "
disabled: "=(vars.miAktiv) ? (vars.miAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[2].split(',')[2]) === '1') : false) "
textColor: "=(vars.miAktiv) ? ( (vars.miAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[2].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: doAktiv
actionVariableValue: "0"
active: "=(vars.doAktiv) ? (vars.doAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[3].split(',')[2]) === '0') : false) "
disabled: "=(vars.doAktiv) ? (vars.doAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[3].split(',')[2]) === '0') : false) "
textColor: "=(vars.doAktiv) ? ( (vars.doAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[3].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: doAktiv
actionVariableValue: 1
active: "=(vars.doAktiv) ? (vars.doAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[3].split(',')[2]) === '1') : false) "
disabled: "=(vars.doAktiv) ? (vars.doAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[3].split(',')[2]) === '1') : false) "
textColor: "=(vars.doAktiv) ? ( (vars.doAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[3].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: frAktiv
actionVariableValue: "0"
active: "=(vars.frAktiv) ? (vars.frAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[4].split(',')[2]) === '0') : false) "
disabled: "=(vars.frAktiv) ? (vars.frAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[4].split(',')[2]) === '0') : false) "
textColor: "=(vars.frAktiv) ? ( (vars.frAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[4].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: frAktiv
actionVariableValue: 1
active: "=(vars.frAktiv) ? (vars.frAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[4].split(',')[2]) === '1') : false) "
disabled: "=(vars.frAktiv) ? (vars.frAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[4].split(',')[2]) === '1') : false) "
textColor: "=(vars.frAktiv) ? ( (vars.frAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[4].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
small: true
text: Aus
action: variable
actionVariable: saAktiv
actionVariableValue: "0"
active: "=(vars.saAktiv) ? (vars.saAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[5].split(',')[2]) === '0') : false) "
disabled: "=(vars.saAktiv) ? (vars.saAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[5].split(',')[2]) === '0') : false) "
textColor: "=(vars.saAktiv) ? ( (vars.saAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[5].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
small: true
text: Ein
action: variable
actionVariable: saAktiv
actionVariableValue: 1
active: "=(vars.saAktiv) ? (vars.saAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[5].split(',')[2]) === '1') : false) "
disabled: "=(vars.saAktiv) ? (vars.saAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[5].split(',')[2]) === '1') : false) "
textColor: "=(vars.saAktiv) ? ( (vars.saAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[5].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-col
config:
style:
margin-right: 10px
white: 50%
slots:
default:
- component: f7-segmented
config:
strong: true
style:
width: 100%
margin-top: 5px
slots:
default:
- component: oh-button
config:
text: Aus
small: true
action: variable
actionVariable: soAktiv
actionVariableValue: "0"
active: "=(vars.soAktiv) ? (vars.soAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[6].split(',')[2]) === '0') : false) "
disabled: "=(vars.soAktiv) ? (vars.soAktiv === '0') : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[6].split(',')[2]) === '0') : false) "
textColor: "=(vars.soAktiv) ? ( (vars.soAktiv === '0') ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[6].split(',')[2]) === '0') ? 'green' : 'red')"
style:
width: 50%
- component: oh-button
config:
text: Ein
small: true
action: variable
actionVariable: soAktiv
actionVariableValue: 1
active: "=(vars.soAktiv) ? (vars.soAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[6].split(',')[2]) === '1') : false) "
disabled: "=(vars.soAktiv) ? (vars.soAktiv === 1) : ((items[props.item].state.split(';')[0].split(',')[2] != NULL) ? ((items[props.item].state.split(';')[6].split(',')[2]) === '1') : false) "
textColor: "=(vars.soAktiv) ? ( (vars.soAktiv === 1) ? 'green' : 'red') : (items[props.item].state.split(';')[0].split(',')[2] == NULL) ? 'red' : (((items[props.item].state.split(';')[6].split(',')[2]) === '1') ? 'green' : 'red')"
style:
width: 50%
- component: f7-row
config:
class:
- justify-content-center
- align-items-center
- text-align-center
style:
margin-top: 20px
margin-buttom: 20px
slots:
default:
- component: oh-button
config:
raised: true
text: Einstellen
action: command
actionItem: =(props.item)
actionFeedback: ok
actionCommand: "= [(vars.moEin === NULL) ? (items[props.item].state.split(';')[0].split(',')[0]) : (vars.moEin)] + ',' + [(vars.moAus === NULL) ? (items[props.item].state.split(';')[0].split(',')[1]) : (vars.moAus)] + ',' + [(vars.moAktiv === NULL) ? (items[props.item].state.split(';')[0].split(',')[2]) : (vars.moAktiv)] + ';' + [(vars.diEin === NULL) ? (items[props.item].state.split(';')[1].split(',')[0]) : (vars.diEin)] + ',' + [(vars.diAus === NULL) ? (items[props.item].state.split(';')[1].split(',')[1]) : (vars.diAus)] + ',' + [(vars.diAktiv === NULL) ? (items[props.item].state.split(';')[1].split(',')[2]) : (vars.diAktiv)] + ';' + [(vars.miEin === NULL) ? (items[props.item].state.split(';')[2].split(',')[0]) : (vars.miEin)] + ',' + [(vars.miAus === NULL) ? (items[props.item].state.split(';')[2].split(',')[1]) : (vars.miAus)] + ',' + [(vars.miAktiv === NULL) ? (items[props.item].state.split(';')[2].split(',')[2]) : (vars.miAktiv)] + ';' + [(vars.doEin === NULL) ? (items[props.item].state.split(';')[3].split(',')[0]) : (vars.doEin)] + ',' + [(vars.doAus === NULL) ? (items[props.item].state.split(';')[3].split(',')[1]) : (vars.doAus)] + ',' + [(vars.doAktiv === NULL) ? (items[props.item].state.split(';')[3].split(',')[2]) : (vars.doAktiv)] + ';' + [(vars.frEin === NULL) ? (items[props.item].state.split(';')[4].split(',')[0]) : (vars.frEin)] + ',' + [(vars.frAus === NULL) ? (items[props.item].state.split(';')[4].split(',')[1]) : (vars.frAus)] + ',' + [(vars.frAktiv === NULL) ? (items[props.item].state.split(';')[4].split(',')[2]) : (vars.frAktiv)] + ';' + [(vars.saEin === NULL) ? (items[props.item].state.split(';')[5].split(',')[0]) : (vars.saEin)] + ',' + [(vars.saAus === NULL) ? (items[props.item].state.split(';')[5].split(',')[1]) : (vars.saAus)] + ',' + [(vars.saAktiv === NULL) ? (items[props.item].state.split(';')[5].split(',')[2]) : (vars.saAktiv)] + ';' + [(vars.soEin === NULL) ? (items[props.item].state.split(';')[6].split(',')[0]) : (vars.soEin)] + ',' + [(vars.soAus === NULL) ? (items[props.item].state.split(';')[6].split(',')[1]) : (vars.soAus)] + ',' + [(vars.soAktiv === NULL) ? (items[props.item].state.split(';')[6].split(',')[2]) : (vars.soAktiv)] "
das Widget benötigt ein String item in welchem die Informationen gespeichert werden.
passend zu dem Widget habe ich eine Rule geschrieben welche bei Veränderung des Items ausgelöst wird:
Code: Alles auswählen
// Einstellungen bitte hier die namen der beiden Rules für ein und aus eintragen
var ruleEin = "Zeitschaltung_ein";
var ruleAus = "Zeitschaltung_aus";
// Einstellungen bitte hier das Item angeben welches die eingestellten Zeiten enthält
var input = "Zeitschaltuhr";
// Hier beginnt das eigentliche script
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
'use strict';
scriptExtension.importPreset("RuleSupport");
scriptExtension.importPreset("RuleSimple");
// Suchen der Rules anhand des namens
var einRule = rules.getAll().stream().filter(function(i){ return i.name == ruleEin }).findFirst().get();
var ausRule = rules.getAll().stream().filter(function(i){ return i.name == ruleAus }).findFirst().get();
// trigger werden hier gespeichert
var triggerEin = {};
var triggerAus = {};
var i;
for (i=0; i<=6; i++) {
// Hilfsvariablen
var day="";
var jahr="";
var cronEin="";
var cronAus="";
var timeEinH = itemRegistry.getItem(input).getState().toString().split(';')[i].split(',')[0].split(':')[0];
var timeEinM = itemRegistry.getItem(input).getState().toString().split(';')[i].split(',')[0].split(':')[1];
var timeAusH = itemRegistry.getItem(input).getState().toString().split(';')[i].split(',')[1].split(':')[0];
var timeAusM = itemRegistry.getItem(input).getState().toString().split(';')[i].split(',')[1].split(':')[1];
var aktive = itemRegistry.getItem(input).getState().toString().split(';')[i].split(',')[2];
// Tag auswählen
switch (i) {
case 0 : { day = "MON"; break; }
case 1 : { day = "TUE"; break; }
case 2 : { day = "WED"; break; }
case 3 : { day = "THU"; break; }
case 4 : { day = "FRI"; break; }
case 5 : { day = "SAT"; break; }
case 6 : { day = "SUN"; break; }
}
// Wenn Tage ausgeschaltet werden diese nur im Jahr 2019 ausgeführt
// Das get sicher noch eleganter also wer eine idee hat immer raus damit.
if (aktive == "1"){
jahr=" *";
}else{
jahr=" 2019"
}
// Erstellung der richtigen cron Expression
cronEin = "0 "+ timeEinM + " " + timeEinH + " ? * " + day + jahr;
cronAus = "0 "+ timeAusM + " " + timeAusH + " ? * " + day + jahr;
// Trigger erstellen
triggerEin[i] = TriggerBuilder.create()
.withId("aTimer" + i)
.withTypeUID("timer.GenericCronTrigger")
.withConfiguration(
new Configuration({
"cronExpression": cronEin
})).build();
triggerAus[i] = TriggerBuilder.create()
.withId("aTimer" + i)
.withTypeUID("timer.GenericCronTrigger")
.withConfiguration(
new Configuration({
"cronExpression": cronAus
})).build();
}
// Trigger in die Rules einsetzen
einRule.setTriggers([triggerEin[0], triggerEin[1], triggerEin[2], triggerEin[3], triggerEin[4], triggerEin[5], triggerEin[6] ]);
ausRule.setTriggers([triggerAus[0], triggerAus[1], triggerAus[2], triggerAus[3], triggerAus[4], triggerAus[5], triggerAus[6] ]);
damit das ganze funktioniert benötigt ihr jetzt noch 2 weitere Rules in welchen ihr eure gewünschten Aktionen eintragt welche beim einschalten und ausschalten ausgeführt werden sollen.
Die von mir geschriebene Rule benötigt nur die entsprechenden Namen und setzt dann die Cron Trigger nach den von euch eingestellten Zeiten.
Ich finde diese Lösung sehr schön da sie ohne Timer auskommt.
durch Nutzung einer persistence kann man das item auch beim Neustart behalten. Dies ist aber nicht zwingend erforderlich da die Einstellungen in den Rules ja fest sind.
Wem das gefällt kann sich dies gerne Kopieren und für eigene Projekte nutzen.
Sollte jemand noch Verbesserungen haben bin ich dafür gerne offen
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.