Help needed with Rules (solved)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
CPT_MAC
Normal user
Posts: 3
Joined: 15 Dec 2019, 18:55

Help needed with Rules (solved)

#1 Post by CPT_MAC » 15 Dec 2019, 19:13

Hi,
please I need some help with rules.

I would like to have the outside light turned on at sunset +15 Minutes and turned off at sunrise -30 Minutes.

So far no problem.

Further I like to get the Garage light turned on, when the Garagedoor are opened and turn off when the door is closed, but only between sunset und sunrise.

The syntax i used just don#t work.

Also in case of a power failure or an reboot the outside light should be on or off depending on night or daytime.

Thx for your help

Code: Select all

On Time#initialized do
  if %sunset% > %systime% and %sunrise% < %systime%
    Gpio,13,0
   else
    Gpio,13,1
  endif
endon

On Clock#Time=All,%sunset+15m% do  //works
  Gpio,13,0
endon

On Clock#Time=All,%sunrise-30m% do  // works
  Gpio,13,1
endon


On Door_open#Switch=1 do
  if %systime% > %sunset% and %systime% < %sunrise%
    Gpio,4,0
   else
    Gpio,4,1
  endif
endon

On Door_open#Switch=0 do   //works
    Gpio,4,1
endon
Last edited by CPT_MAC on 19 Dec 2019, 22:31, edited 1 time in total.

User avatar
ThomasB
Normal user
Posts: 535
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Help needed with Rules

#2 Post by ThomasB » 16 Dec 2019, 03:55

Maybe your local time is incorrect. To confirm, go to the Main tab and review the reported value. It should match your actual local time. If incorrect, use Tools=>Advanced and update Timezone Offset entry.

- Thomas

CPT_MAC
Normal user
Posts: 3
Joined: 15 Dec 2019, 18:55

Re: Help needed with Rules

#3 Post by CPT_MAC » 16 Dec 2019, 10:19

Thanks for your reply Thomas.

But this is not the case. This part works excellent:

On Clock#Time=All,%sunset+15m% do //works
Gpio,13,0
endon

On Clock#Time=All,%sunrise-30m% do // works
Gpio,13,1
endon

I think that I have to use maybe brackets at some points or something else with the syntax I used. Or maybe the format of systime do not match the format of sunset or sunrise.

It does not matter at what time it is, the program always jump to:
else
Gpio,4,1
endif
endon

and set the gpio 4 to high

wim16
Normal user
Posts: 79
Joined: 01 May 2017, 20:35

Re: Help needed with Rules

#4 Post by wim16 » 16 Dec 2019, 10:46

Maybe the problem is in your if statement.
When systime > sunset it is often also > sunrise (on the same day) and thus the result will be false.

User avatar
grovkillen
Core team member
Posts: 3438
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Help needed with Rules

#5 Post by grovkillen » 16 Dec 2019, 11:55

wim16 wrote:
16 Dec 2019, 10:46
Maybe the problem is in your if statement.
When systime > sunset it is often also > sunrise (on the same day) and thus the result will be false.
Yep, that's it. Let me think about that one for a while and get back with a suggestion on the rules.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
ThomasB
Normal user
Posts: 535
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Help needed with Rules

#6 Post by ThomasB » 16 Dec 2019, 19:22

Good catch. For rule simplicity, it would be nice to have a %isDaylight% bool variable. And perhaps a %isTwilight% bool var too. :)

Maybe something like this clumsy workaround would help (example is untested):

Code: Select all

On Time#initialized do
  if %systime% < %sunrise% and %systime% < 12:00:00  // Early morning, Is Dark outside.
   let,15,1
  else 
   let,15,0
  endif

  if %systime% > %sunset% and %systime% > 12:00:00  // Late evening, Is Dark outside.
   let,16,1
  else 
   let,16,0
  endif
 
  if %v15%=1 or %v16%=1  // Is Dark outside.
   Gpio,13,0  // Turn On
  else 
   Gpio,13,1  // Turn Off
  endif
 endon
Note: Enter accurate Lat & Long coordinates in Tools=>Advanced (Location Settings section). Confirm the settings are correct by going to Tools=>System Variables and sanity check %sunset% & %sunrise% values.

Hopefully someone posts a better solution. BTW, this rule example would need to be changed to work in geo locations with unusual sunrise/sunset times (Iceland, etc.).

- Thomas

Flying Domotic
Normal user
Posts: 36
Joined: 27 Aug 2019, 23:57

Re: Help needed with Rules

#7 Post by Flying Domotic » 17 Dec 2019, 11:47

You may try :

Code: Select all

  if %systime% > %sunset% or %systime% < %sunrise%
    Gpio,13,1
   else
    Gpio,13,0
  endif
  
Concerning the door linked light, you could have a small side effect when closing the door during the day: this will turn light off

CPT_MAC
Normal user
Posts: 3
Joined: 15 Dec 2019, 18:55

Re: Help needed with Rules

#8 Post by CPT_MAC » 17 Dec 2019, 18:12

Thank you Thomas.

Your workaround works after reboot. This is very good, because ofter reboot the outside Light will be on or off in regards to Daytime or Nighttime.

Further to turn the light on at sunset and off at sunrise with or without offset works.

Perfect so far.

The last thing is to have the Garage light inside on when the Garagentor is open during Nighttime and to keep it off during daytime.

Thank you flying Domotic

Your workaround works too, at least to turn the Garagelight on when the Garagentor at night is open and off when closed. Daytime I will check tomorrow.

Code: Select all

On Door_open#Switch=1 do
  if %systime% > %sunset% or %systime% < %sunrise%
    Gpio,4,0
   else
    Gpio,4,1
  endif
endon

User avatar
ThomasB
Normal user
Posts: 535
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Help needed with Rules

#9 Post by ThomasB » 17 Dec 2019, 18:34

Thank you Thomas. Your workaround works after reboot. This is very good, because ofter reboot the outside Light will be on or off in regards to Daytime or Nighttime.
Thanks for the feedback. Since Domotic's time compare logic is working you should also use it in the Time#initialized rule instead of my long / clumsy workaround.

- Thomas

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests