I am trying to use an astro-binding rule together with a timer rule, but I havent been successful yet.
After sunset I’d like 2 switches being activated by a 3rd switch for a certain period of time.
The astro-binding triggers but nothing happens when that 3rd switch (Tor) is pressed/switched.
No rule faults in my LogFile:
var Timer timer = null
rule "Carportbeleuchtung"
when
Channel 'astro:sun:home:set#event' triggered START
then
if ((Tor.state==ON) && (timer === null)) {
Shelly4.sendCommand(ON)
Shelly2.sendCommand(ON)
timer = createTimer(now.plusMinutes(2) [|
(Shelly4.sendCommand(OFF) || Shelly2.sendCommand(OFF))
])
}
timer = null
end
Oh,
and second question. I just noticed that sunset-event only lasted for 14 minutes and triggered END after that. Is there an event like for example “night” that can be used instead, so that the rule still works after the end of the sunset??
Tor.state must already be ON when the astro event occurs for the Rule to do anything. Do you mean to do the actions when Tor changed to ON but only at a certain time of day? If so you need to trigger the Rule on Tor and then check to see if now is at the right time.
Rules are event based. At sunset the Rule triggers and runs just once.
First of all, the sunset state lasts for 14 minutes. The sunset#event is an instant in time. Rules are triggered by events so this Rule only triggers at the instant of sunset. It doesn’t get “enabled” for the whole sunset period which seems to be your mistaken understanding.
See Design Pattern: Time Of Day for an example which should answer your second question and show you how to do this correctly.
Thank you both for your explanations.
I really misunderstood the event concept. Rikoshak, your Design Pattern looks promising, i will work myself throug that.