Turn On Light Before Dawn and At Dusk

Michael Ingraham 2019-08-12 12:01:44 -04:00
parent 74621d88b1
commit 6a49d1223a
1 changed files with 64 additions and 0 deletions

@ -16,6 +16,7 @@
- [Toggle a Relay only when holding the button for 2 seconds](#toggle-a-relay-only-when-holding-the-button-for-2-seconds) - [Toggle a Relay only when holding the button for 2 seconds](#toggle-a-relay-only-when-holding-the-button-for-2-seconds)
- Using Sunrise and Sunset - Using Sunrise and Sunset
- [Make sure light is on at night](#make-sure-light-is-on-at-night) - [Make sure light is on at night](#make-sure-light-is-on-at-night)
- [Turn On Light Before Dawn and At Dusk](#Turn-On-Light-Before-Dawn-and-At-Dusk)
- [Enable a PIR Switch only at night](#enable-a-pir-switch-only-at-night) - [Enable a PIR Switch only at night](#enable-a-pir-switch-only-at-night)
- [PIR Configuration](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method) - [PIR Configuration](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method)
- [Using clock timer to control a luminance-triggered switch only in mornings](#using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings) - [Using clock timer to control a luminance-triggered switch only in mornings](#using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings)
@ -626,6 +627,69 @@ The previous rules are conditionals that represent the following logic:
IF %time%>%sunset DO power1 1 / IF %time%<%sunrise DO power1 1 IF %time%>%sunset DO power1 1 / IF %time%<%sunrise DO power1 1
[Back To Top](#top)
------------------------------------------------------------------------------
#### Turn On Light Before Dawn and At Dusk
Turn on light at dusk until your nighttime and again in the morning before dawn.
What if the sun sets after your nighttime, as in during the summer? Then the timer will turn off the light at "night", but then the Sunset timer will turn it on again, so it stays on all night.
```
Rule1
on Time#Initialized do event chkSun endon
on Time#Minute=%sunset% do event chkSun endon
on event#chkSun do backlog var1 0; event chkSunrise=%time%; event chkSunset=%time%; event chkmorn=%time%; event chknight=%time%; event setPower endon
on event#chkSunrise<%sunrise% do var1 1 endon
on event#chkSunset>=%sunset% do var1 1 endon
on event#chkmorn<%mem1% do var1 0 endon
on event#chknight>=%mem2% do var1 0 endon
on event#setPower do power1 %var1% endon
```
```
Backlog mem1 360; mem2 1350
Rule1 1
```
- **Explanation:**
\# When device restarts, calculate if the light should be on or off
`on Time#Initialized do event chkSun endon`
\# At Sunset, calculate if the light should be on or off
`on Time#Minute=%sunset% do event chkSun endon`
\# Calculate if the light should be on or off
`on event#chkSun do backlog `
&nbsp;&nbsp;&nbsp;&nbsp;\# Assume off
&nbsp;&nbsp;&nbsp;&nbsp;`var1 0; `
&nbsp;&nbsp;&nbsp;&nbsp;\# Trigger each event with the current time
&nbsp;&nbsp;&nbsp;&nbsp;`event chkSunrise=%time%; event chkSunset=%time%; event chkmorn=%time%; event chknight=%time%; event setPower `
`endon`
\# If before sunrise, turn on
`on event#chkSunrise<%sunrise% do var1 1 endon`
\# If past sunset, turn on
`on event#chkSunset>=%sunset% do var1 1 endon`
\# But if before Morning time (`mem1`), do not turn on
`on event#chkmorn<%mem1% do var1 0 endon`
\# Or if after Night time (`mem2`), do not turn on
`on event#chknight>=%mem2% do var1 0 endon`
\# Perform on/off state
`on event#setPower do power1 %var1% endon`
\# Set variables for Morning (06h00) and Night (22h30) times
`Backlog mem1 360; mem2 1350`
\# Turn on the rule set
`Rule1 1`
[Back To Top](#top) [Back To Top](#top)