Help needed with Rules (solved)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
CPT_MAC
New user
Posts: 5
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: 1064
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
New user
Posts: 5
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: 88
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: 3621
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: 1064
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: 37
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
New user
Posts: 5
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: 1064
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

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Help needed with Rules (solved)

#10 Post by Dick60 » 11 Mar 2023, 07:59

I try to implement the solution discussed in this topic but it does not work for me. I use the mega-20220809_57b0c0c and a mega-20230306 firmware on an ESP8266 (on both the rule is not working).
Coordinate are set, both %sunrise% %sunset% in the CMD are working and give the correct time. Is there a reason why it does not work?

Code: Select all

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

  if %systime% > %sunset% and %systime% > 12:00:00  // Late evening, Is Dark outside.
   let,7,1
  else 
   let,7,0
  endif
 
  if %v6%=1 or %v7%=1  // Is Dark outside.
   Gpio,14,1  // Turn On
  else 
   Gpio,14,0  // Turn Off
  endif
 endon

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help needed with Rules (solved)

#11 Post by Ath » 11 Mar 2023, 09:21

Does the on time#initialized do event get fired? You could add a few logentry commands there and watch the log, preferrably via serial, as this event can be generated quite early after boot, and will probably only be generated once...
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Help needed with Rules (solved)

#12 Post by Dick60 » 11 Mar 2023, 12:27

as far I can see, it is not started during reboot.I did some more testing and simplified the rule

Code: Select all

On Time#Initialized do
  if [Sunrise#State]=0 and %systime% > %sunrise%
   Gpio,4,1
  else 
   Gpio,4,0
  endif
endon
Also this Event was not started.
Tested The %systime% and %sunrise% in the CMD aria, the results are As expected, correct.

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Help needed with Rules (solved)

#13 Post by Dick60 » 12 Mar 2023, 18:40

latest development, I don't know why the previous solution did not work but this works for me

Code: Select all

on Clock#Time=All,**:** do
 if %systm_hm% < %sunrise% and %systime% < 12:00:00  // Early morning, Is Dark outside
Let,2,0
//notify 1,"sunset!"
else
let,2,1
endif

if %systime% > %sunset% and %systime% > 12:00:00  // Late evening, Is Dark outside.
Let,3,0
//notify 1,"sunrise!"
else
let,3.1 
endif

if %v2%=0 or %v3%=0  // Is Dark outside.
   Gpio,4,0  // Turn On
  else 
   Gpio,4,1  // Turn Off
  endif
 endon

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help needed with Rules (solved)

#14 Post by Ath » 12 Mar 2023, 19:49

The major difference is that your code is now executed every minute, instead of only once, when Time#Initialized is triggered. That is most likely the 'cause' it is now working :)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 26 guests