Quite a newbie here with openhab2 (and java) and as I try my first rules I see unexpected results.
I don’t have much actors currently, 2 hue items and a number of Brennenstuhl switchable plugs which I drive with raspberry-remote/send.
From a sitemap with dedicated switches this works fine and reliable.
Now, to establish a cycle of daily phases, I created 8 state Buttons and a rule file with event handlers for each state
Switch StateBtn_early "Frühlicht" <"light"> (gStateBtn)
Switch StateBtn_morning "Morgenlicht" <"light"> (gStateBtn)
Switch StateBtn_day "Taglicht" <"light"> (gStateBtn)
Switch StateBtn_away "Weglicht" <"light"> (gStateBtn)
Switch StateBtn_evening "Abendlicht" <"light"> (gStateBtn)
Switch StateBtn_late "Spätlicht" <"light"> (gStateBtn)
Switch StateBtn_goodnight "GuteNachtlicht" <"light"> (gStateBtn)
Switch StateBtn_night "Nachtlicht" <"light"> (gStateBtn)
There is another frame in that sitemap with all my stateBtn lined up. I can click a button there, the update (or command, or change) is detected, the handler gets called, some things are done. This is where the problems start.
Among the things to do there hue actions, change the HSB of the items, and those work reliable.
Then there are plugs to switch, and those actions happen, or they do not. I suspect the raspberry-remote/send construction is challenged when a sequence of commands come in short succession. I tried to insert a wait() but the RuleEngine erred “cannot invoke method”
And finally, there is a eventhandler for updates to a String item holding the current state which is supposed to clear the ui, set all switches to off exceept the current one. It works, but only in half of the times. The other times apparently nothing happens, or some switches are cleared while others stay in visual on position.
All in all it feels like I’m trying to ride the horse backwards so any advice how to approach this would be most appreciated.
var String currentPhase
var String ColorHue
var String[] statesArray = newArrayList("early","morning","day","away","evening","late","goodnight","night")
// StateBtn_early
rule "rule triggered by StateBtn_early"
when
Item StateBtn_early received update
then
if (StateBtn_early.state == ON) {
currentPhase="early"
ColorHue="270,100,3"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
// redlight aus
steckdose08Switch.sendCommand("OFF")
Current_BtnState.postUpdate("early")
}
end
// StateBtn_morning
rule "rule triggered by StateBtn_morning"
when
Item StateBtn_morning received update
then
if (StateBtn_morning.state == ON) {
currentPhase="morning"
ColorHue="45,100,23"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
Current_BtnState.postUpdate("morning")
}
end
// StateBtn_day
rule "rule triggered by StateBtn_day"
when
Item StateBtn_day received update
then
if (StateBtn_day.state == ON) {
currentPhase="day"
ColorHue="90,100,33"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
Current_BtnState.postUpdate("day")
}
end
// StateBtn_away
rule "rule triggered by StateBtn_away"
when
Item StateBtn_away received update
then
if (StateBtn_away.state == ON) {
currentPhase="away"
ColorHue="135,100,1"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
Current_BtnState.postUpdate("away")
}
end
// StateBtn_evening
rule "rule triggered by StateBtn_evening"
when
Item StateBtn_evening received update
then
if (StateBtn_evening.state == ON) {
currentPhase="evening"
ColorHue="18,100,43"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
steckdose16Switch.sendCommand("ON")
Current_BtnState.postUpdate("evening")
}
end
// StateBtn_late
rule "rule triggered by StateBtn_late"
when
Item StateBtn_late received update
then
if (StateBtn_late.state == ON) {
currentPhase="late"
ColorHue="358,100,7"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
steckdose16Switch.sendCommand("ON")
steckdose02Switch.sendCommand("ON")
Current_BtnState.postUpdate("late")
}
end
// StateBtn_goodnight
rule "rule triggered by StateBtn_goodnight"
when
Item StateBtn_goodnight received update
then
if (StateBtn_goodnight.state == ON) {
currentPhase="goodnight"
ColorHue="7,100,13"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
ColorHue="352,100,13"
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
// balkon licht an
steckdose03Switch.sendCommand("ON")
steckdose08Switch.sendCommand("ON")
steckdose01Switch.sendCommand("ON")
Current_BtnState.postUpdate("goodnight")
}
end
// StateBtn_night
rule "rule triggered by StateBtn_night"
when
Item StateBtn_night received update
then
if (StateBtn_night.state == ON) {
currentPhase="night"
// office aus
steckdose16Switch.sendCommand("OFF")
//wait(2)
steckdose03Switch.sendCommand("OFF")
steckdose08Switch.sendCommand("OFF")
steckdose01Switch.sendCommand("OFF")
Current_BtnState.postUpdate("night")
ColorHue="315,100,3"
hue_0210_001788a718e6_1_color.sendCommand(ColorHue)
hue_0210_001788a718e6_2_color.sendCommand(ColorHue)
}
end
// Current_BtnState received update
rule "rule triggered by Current_BtnState"
when
Item Current_BtnState received update
then
var String curState = Current_BtnState.state.toString()
for ( aState : statesArray) {
if (aState==curState) {
//nix?
} else {
postUpdate("StateBtn_"+aState,"OFF")
}
}
end
// if(Astro_Night_State.state != OFF)
rule "rule triggered by Astro_Night_State changed"
when
Item Astro_Night_State changed
then
if (Astro_Night_State == OFF) {
StateBtn_early.sendCommand("ON")
} else {
StateBtn_evening.sendCommand("ON")
}
end