Stuck with SunSet Rule

Hi all,

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

The Switch I created

Switch Sunset_Event {astro=“planet=sun, type=set, property=start”}

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.

Any Ideas how to solve this?

Regards
Joerg

I’m not sure Astro changes the state of the switch or if it just sets it to ON and it stays there.

Try received command or received update as your trigger. I successfully use received update in my rules.

1 Like

Thanks, just changed it to “received update ON” and will see if it starts tomorrow :smile:

Cheers
Joerg

Hi Jörg

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 {...}

Regards
Dieter

According to the wiki,

“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.

Hi @steve1
It is relevant if your rule contains an if statement that checks whether or not the switch is ON (it won’t be). Otherwise you are right :wink:

Regards
Dieter

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

No, worries. I think any information that helps diagnose incorrect or surprising binding behaviors is very useful.

Hi all,

many thanks for the right hints.

The following works like a charm and do the Job.

rule Sunset_Event
when
	Item Sunset_Event received update ON
then
		pushNotification("Information", "Sunset")
		Lampe_1.sendCommand(ON)
		Lampe_2.sendCommand(ON)
	// Christmas
			if (SpecialDay == "sunday_in_commemoration_of_the_dead") {
				if (!pushNotification("" + SpecialDay + "", "No Deco Lights today!!")) {
				sendMail("Prowlkey@api.prowlapp.com", "" + SpecialDay + "", "No Deco Lights today!!")
				}
			} else {
			Steckd_1.sendCommand(ON)
			Steckd_2.sendCommand(ON)
			Lampe_3.sendCommand(ON)
			}
end

Regards
Joerg