%sunrise% and %sunset% rules do not work any more

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

%sunrise% and %sunset% rules do not work any more

#1 Post by _Cyber_ » 16 May 2022, 06:52

hello,

%sunrise% and %sunset% rules do not work any more.
I am using ESP_Easy_mega_20220427_normal_ESP32_4M316k with NTP as time source.

Local Time: 2022-05-16 06:43:46
Time Source: NTP
Time Wander: -0.026 [msec/sec]

Latitude and Longitude are accordingly set.

Variables are set:
%sunset% 20:45 20%3a45
%sunrise% 5:39 5%3a39

Cache rules and rule cache event order are ticked.

I have three on clock#time rules configured. the Clock#Time=All,**:** works. the sunset and sunrise are not triggered at all.

the rules did work in the past, I think they stopped working after update.

Code: Select all

on Clock#Time=All,%sunset% do
 Let,2,100
 asyncevent,Closeall
 notify 1,"sunset!"
endon

on Clock#Time=All,%sunrise% do
 Let,2,0
 TaskValueSet,5,2,0
 notify 1,"sunrise!"
 //asyncevent,Openall
endon

on Clock#Time=All,**:** do
 SendToHTTP,192.168.0.250,80,/apcucollector.php?smartswitch=%sysname%&ipv4=%ip%&uptime=%uptime%&load=%sysload%&freeram=%sysheap%&rssi=%rssi%&sunrise=%sunrise%&sunset=%sunset%&SZ=[SZ#M];[SZ#S];&Z1=[Z1#M];[Z1#S];[Z1#SL];[Z1#SR];&Z2=[Z2#M];[Z2#S];[Z2#SL];[Z2#SR];&Z3=[Z3#M];[Z3#S];[Z3#SL];[Z3#SR];
endon
any hints what i can try? :)

thanks.

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

Re: %sunrise% and %sunset% rules do not work any more

#2 Post by Ath » 16 May 2022, 07:35

Does it work if you disable the "Cache rules" setting?
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: %sunrise% and %sunset% rules do not work any more

#3 Post by TD-er » 16 May 2022, 09:01

Cache rules is probably not the issue here, it is the optimization of the rules order.
Please uncheck: Optimize Rules Cache Event Order

The problem is that you have several event handling blocks starting with the same partial event.
One of the optimizations I made is to re-order the events in memory based on how often they are used.
But this one really needs to be in the specific order.

I knew there would be some issues, so therefore I added this checkbox, but I could not think of one when I wrote the optimization.

_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

Re: %sunrise% and %sunset% rules do not work any more

#4 Post by _Cyber_ » 16 May 2022, 09:56

thanks, I will report back if disabling "Optimize Rules Cache Event Order" fixes. :-)

BR
Alois

//Edit: at least without reboot this did not help. although I received at midnight the %sunset% email ... :o
I rebooted now and will have a further look today evening and tomorrow morning.

_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

Re: %sunrise% and %sunset% rules do not work any more

#5 Post by _Cyber_ » 18 May 2022, 06:45

hm, no, again the sunset email was sent at midnight, no sunrise at all.
I have now merged the three Clock#Time Rules into one on - endon block with if-clauses inside. and again enabled the "Optimize Rules Cache Event Order" - lets have a look if it is working then ...
disabling the "Cache rules" completely is regrettably on this device not good at it is then more or less not useable :shock:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: %sunrise% and %sunset% rules do not work any more

#6 Post by TD-er » 18 May 2022, 09:48

You can also test it by setting the time/date right before sunrise/sunset, so you don't need to wait almost a day ;)
See the "datetime" command: https://espeasy.readthedocs.io/en/lates ... l-commands

_Cyber_
Normal user
Posts: 113
Joined: 20 Oct 2019, 09:46

Re: %sunrise% and %sunset% rules do not work any more

#7 Post by _Cyber_ » 19 May 2022, 07:58

TD-er wrote: 18 May 2022, 09:48 You can also test it by setting the time/date right before sunrise/sunset, so you don't need to wait almost a day ;)
See the "datetime" command: https://espeasy.readthedocs.io/en/lates ... l-commands
but then our shutters start to twinkle around and my wife already now always says it's crazy what I am doing :-)

so with this rule everything works well:

Code: Select all

on Clock#Time=All,**:** do
 if %systm_hm% = %sunset%
  Let,2,100
  asyncevent,Closeall
  notify 1,"sunset!"
 elseif %systm_hm% = %sunrise%
  Let,2,0
  TaskValueSet,5,2,0
  notify 1,"sunrise!"
  //asyncevent,Openall
 else
  SendToHTTP,192.168.0.250,80,/apcucollector.php?smartswitch=%sysname%&ipv4=%ip%&uptime=%uptime%&load=%sysload%&freeram=%sysheap%&rssi=%rssi%&sunrise=%sunrise%&sunset=%sunset%&SZ=[SZ#M];[SZ#S];&Z1=[Z1#M];[Z1#S];[Z1#SL];[Z1#SR];&Z2=[Z2#M];[Z2#S];[Z2#SL];[Z2#SR];&Z3=[Z3#M];[Z3#S];[Z3#SL];[Z3#SR];
 endif
endon
btw, I have some other recent firmwares running with similar constructs:

Code: Select all

on [Water#Count]!=0 do
...
endon

on [Water#Count]=0 do
...
endon
or:

Code: Select all

on GPIO#2=1 do
...
endon

on GPIO#2=0 do
...
endon
and they work flawless.
but those are ESP8266 where the "Enable Rules Cache" is not operative caused by less memory, or did I get it wrong in the PR messages?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: %sunrise% and %sunset% rules do not work any more

#8 Post by TD-er » 19 May 2022, 08:48

It's about whether you have multiple rules blocks which can match an event.
The sorting of the rules blocks is a speed optimization where the most frequently used is then positioned more to the front of the list of blocks.
The "on Clock#Time=All,**:** do" line will match more frequently compared to more specific ones and thus end up to the front of the list.

You had it positioned later in the rules, which is how it should be in this specific use case.
So for this reason you need to disable this optimization to reorder rules blocks.
I think I will disable it as default for newer builds.

The other example you gave will work just fine, unless you make a more generic one.
For example this one will also fail:

Code: Select all

on [Water#Count]!=0 do
...
endon

on Water#Count do
...
endon
N.B. don't use [] in "on...do" lines as this may have strange side effects.
It may be changed into "on 1!=0 do" which is valid and then the matching rule was executed and thus the actual event will not be executed.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests