Rules with sunset sunrise

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
edstobi
Normal user
Posts: 39
Joined: 28 May 2020, 20:33

Rules with sunset sunrise

#1 Post by edstobi » 16 Mar 2021, 21:21

HI
I am using ESP8266 with 20112 - Mega.
I do have a relay for output and a switch for input.
I can activate the relay with the Switch on Rules 1.
The switch is for a lamp "on" or "auto" mode.

Code: Select all

on System#Boot do
  gpio,4,0
  timerSet,1,10
endon


on Switch#Switch=1 do
  if [Relay#Relay]=1
    gpio,4,0
  else
    gpio,4,1
  endif
endon
on Switch#Switch=0 do
  if [Relay#Relay]=0
    gpio,4,1
  else
    gpio,4,0
  endif
endon
on Rules 2 I want to do the auto mode:

Code: Select all

on Clock#Time=%sunrise% do    //  sunrise.
 event,Off                    // turn off relay
 endon

on Clock#Time=%sunset% do    //  sunset...
 event,On                     // turn on relay
 endon

on Clock#Time=All,01:00 do    //  01:00 Uhr aus 
  event,Off                     // turn off relay
endon

on Clock#Time=All,05:00 do    //  05:00 Uhr aus 
  event,On                    // turn on relay
endon

on On do
  gpio,4,1
endon

on Off do
  gpio,4,0
endon
I shooed hear at last a click from the relay or see it in the lock a action of the espeasy.
But ther is no reaction.

where do I do the error of this thinking?
THX

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

Re: Rules with sunset sunrise

#2 Post by TD-er » 16 Mar 2021, 22:44

The first rules can be simplified as the do the same.

Code: Select all

on Switch#Switch=1 do
  if [Relay#Relay]=1
    gpio,4,0
  else
    gpio,4,1
  endif
endon
on Switch#Switch=0 do
  if [Relay#Relay]=0
    gpio,4,1
  else
    gpio,4,0
  endif
endon
Apart from the eventvalue both blocks do the same, so you can simplify it to:

Code: Select all

on Switch#Switch do
  if [Relay#Relay]=1
    gpio,4,0
  else
    gpio,4,1
  endif
endon
And it can be even shorter, as can be seen in the documentation: https://espeasy.readthedocs.io/en/lates ... red-values

Code: Select all

on Switch#Switch do
  gpio,4,![Relay#Relay]
endon


... unless it was not intended this was the same in both cases.

edstobi
Normal user
Posts: 39
Joined: 28 May 2020, 20:33

Re: Rules with sunset sunrise

#3 Post by edstobi » 17 Mar 2021, 12:09

WAU
that is a nice compact way!
May I ask for this code part.
on Clock#Time=%sunrise% do // sunrise
event,Off // turn off relay
endon

on Clock#Time=%sunset% do // sunset...
event,On // turn on relay
endon

on Clock#Time=All,01:00 do // 01:00 Uhr aus
event,Off // turn off relay
endon

on Clock#Time=All,05:00 do // 05:00 Uhr aus
event,On // turn on relay
endon

on On do
gpio,4,1
endon

on Off do
gpio,4,0
endon
That is on retaking, the fix time is switching but sunset and sunrise do not trigger the expected result
THX
edstobi

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

Re: Rules with sunset sunrise

#4 Post by TD-er » 17 Mar 2021, 12:20

Not 100% sure if the parser may accept "On" as an event or misinterprets it as the start of a block.
It should work, but when in doubt you may want to change that name to test if things start working then.

About the clocktime matching, see the example here:
https://espeasy.readthedocs.io/en/lates ... ore-events

Code: Select all

on Clock#Time=All,12:00 do //will run once a day at noon
 GPIO,2,1
endon

on Clock#Time=All,**:30 do //will run half past every hour
 GPIO,2,1
endon

on Clock#Time=All,%sunrise% do //will run at sunrise  (%sunset% is also available)
 GPIO,2,1
endon
As you can see, the clock#time event does need to have a specific format, starting with the days of the week and then the time, separated with a comma.


And as extra information about calling the event.
When calling an event like this, it is called immediately, thus calling a new rule parsing instance on top of the current one.
For small event blocks like this that's not a big deal, but for a number of nested events you may run out of resources.
So whenever possible, try to use "asyncevent" instead of "event".
It will append the new event to a queue which is processed later.

edstobi
Normal user
Posts: 39
Joined: 28 May 2020, 20:33

Re: Rules with sunset sunrise

#5 Post by edstobi » 17 Mar 2021, 22:21

THX to all
The problem is solved.
it was the missing "ALL" for sunrise and sunset

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Rules with sunset sunrise

#6 Post by Metatron » 20 Mar 2021, 09:42

Hello,

so far, well understood, thank you.
But what do I do, if I want something to happen, half an hour before sunrise?
Any hint, for a newbie, please?

Propably the easiest way is, to move my coordinates further to the east, right?

Regards, Metatron
Last edited by Metatron on 20 Mar 2021, 10:10, edited 1 time in total.

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

Re: Rules with sunset sunrise

#7 Post by Ath » 20 Mar 2021, 10:04

Metatron wrote: 20 Mar 2021, 09:42 But what do I do, if I want something to happen, half an hour before sunrise?
The variables for sunrise and sunset support adding or subtracting minutes or hours, the syntax is like %sunrise-30m% and %sunset+2h% etc. This is only supported for these 2 variables.
/Ton (PayPal.me)

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Rules with sunset sunrise

#8 Post by Metatron » 20 Mar 2021, 10:10

Wow, cool, thanks!

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

Re: Rules with sunset sunrise

#9 Post by TD-er » 20 Mar 2021, 13:29

See also the system variables page on your ESPEasy node (only present on 'normal' or 'custom' builds) for more ideas.
They are also described here: https://espeasy.readthedocs.io/en/lates ... -variables

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 31 guests