I’m trying to ceate a rule which Switches my Christmas Lights on when Sunset starts.
I used the following Rule
rule Sunset_Event
when
Item Sunset_Event changed
then
if (Sunset_Event.state == ON) {
pushNotification(“Information”, “Sonnenuntergang”)
Lampe_1.sendCommand(ON)
Lampe_2.sendCommand(ON)
// Weihnachtsschaltung
if (SpecialDay == “sunday_in_commemoration_of_the_dead”) {
if (!pushNotification("" + SpecialDay + “”, “Heute gibt es keine Beleuchtung!!”)) {
sendMail("key@api.prowlapp.com", “” + SpecialDay + “”, “Heute gibt es keine Beleuchtung!!”)
}
} else {
Christmas_Light_1.sendCommand(ON)
Christmas_Light_2.sendCommand(ON)
Christmas_Light_3.sendCommand(ON)
}
}
end
But: It doesnt’t work and I trust it’s because as soon as sunset starts and Updates the Switch is is immediately switched off again and that fast that “” doesn’t recognized it.
As @rlkoshak mentioned you could do a received update or you simply use changed to ON instead of changed. Then remove the if statement and everything is fine.
The event only triggers the switch and is not persistant. So you might have runtime issues if you do a separate test. If you really need to do it, you should do a timecheck like if(now>=sunset) then {...}
“If you bind it to a Switch, a event is scheduled and the state of the Switch is updated to ‘‘ON’’, immediately followed by a ‘‘OFF’’ at the calculated time.”.
Now, whether it actually behaves that way or not is a different matter.
Agreed. I was responding to whether the item changed event would trigger the rule. If the switch is turned ON and then OFF immediately by Astro an updated event will trigger the rule twice, but that could be compensated for with conditions in the rule body.
I see, we are on the same side…
Only problem is, that if your “in-rule-condition” checks for switch == ON you have a good chance that this is never true, every else check (including switch==OFF and time>=sunset) will most likely be true every time but both is not 100% true. So if you want to spend your time searching for such timing-based errors (can be very funny indeed, I guess you know that ;-)) go ahead…
Regards
Dieter
PS: @steve1: Please don’t get me wrong. According to your other posts I guess you are an experienced Java developer and have already spent some hours/days searching for such errors. I work in SW-Test and spending my time looking for things that might not work goes also to my private topics