sunrise/sunset to be used in rule

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
TungstenE2
Normal user
Posts: 119
Joined: 03 Apr 2018, 21:46

sunrise/sunset to be used in rule

#1 Post by TungstenE2 » 30 May 2018, 08:35

Hi all,

I would like to use sunrise/sunset time in a rule (eg sunrise + 30min) on a Wemos D1 mini using latest mega build.
How to do this? An external HTTP request would be good, but not to a lokal controler.
I want to be independent from another controler.

Any ideas or tipps?

thx

User avatar
enesbcs
Normal user
Posts: 535
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: sunrise/sunset to be used in rule

#2 Post by enesbcs » 01 Jun 2018, 13:48

TungstenE2 wrote: 30 May 2018, 08:35 Hi all,
I would like to use sunrise/sunset time in a rule (eg sunrise + 30min) on a Wemos D1 mini using latest mega build.
How to do this? An external HTTP request would be good, but not to a lokal controler.
I want to be independent from another controler.
Any ideas or tipps?
thx
You need to know the date and time at least (NTP or RTC), and you based on it you could use something like this library:
https://github.com/dmkishi/Dusk2Dawn

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: sunrise/sunset to be used in rule

#3 Post by papperone » 01 Jun 2018, 16:45

enesbcs wrote: 01 Jun 2018, 13:48
TungstenE2 wrote: 30 May 2018, 08:35 Hi all,
I would like to use sunrise/sunset time in a rule (eg sunrise + 30min) on a Wemos D1 mini using latest mega build.
How to do this? An external HTTP request would be good, but not to a lokal controler.
I want to be independent from another controler.
Any ideas or tipps?
thx
You need to know the date and time at least (NTP or RTC), and you based on it you could use something like this library:
https://github.com/dmkishi/Dusk2Dawn
you need as well Longitude and Latitute, I think it's too much to implement this in EspEasy, I do this already for my garden lights but I do it in my NodeRed@RasPi :mrgreen:
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

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

Re: sunrise/sunset to be used in rule

#4 Post by TD-er » 01 Jun 2018, 22:32

I think it is a useful feature, so could you add an issue for it?


hooijschuur
Normal user
Posts: 3
Joined: 27 Sep 2015, 09:01

Re: sunrise/sunset to be used in rule

#6 Post by hooijschuur » 01 Jul 2018, 18:21

Is IT also possible tot post An example rule
There are examples but not for Sunset etc.

TungstenE2
Normal user
Posts: 119
Joined: 03 Apr 2018, 21:46

Re: sunrise/sunset to be used in rule

#7 Post by TungstenE2 » 04 Jul 2018, 08:41

I was just about to test it.

New %sunrise% and %sunset% variables were added, but I am not sure about the syntax to be used in rules.

Is there a way to test the variables?

https://www.letscontrolit.com/wiki/inde ... _Variables

TungstenE2
Normal user
Posts: 119
Joined: 03 Apr 2018, 21:46

Re: sunrise/sunset to be used in rule

#8 Post by TungstenE2 » 04 Jul 2018, 14:47

could someone give an example rule how to use %sunrise% and %sunset% variables?

on this page nothing is mentioned on how to use variables:
https://www.letscontrolit.com/wiki/inde ... rial_Rules

would this be something like this?

Code: Select all

on  %sunrise% do
 if <test>
   <action>
   <action>
 endif
endon

User avatar
enesbcs
Normal user
Posts: 535
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: sunrise/sunset to be used in rule

#9 Post by enesbcs » 04 Jul 2018, 18:04

TungstenE2 wrote: 04 Jul 2018, 14:47 could someone give an example rule how to use %sunrise% and %sunset% variables?

on this page nothing is mentioned on how to use variables:
https://www.letscontrolit.com/wiki/inde ... rial_Rules

would this be something like this?

Code: Select all

on  %sunrise% do
 if <test>
   <action>
   <action>
 endif
endon
I am pretty sure that variables do not ment to be used in that way.
I think that Clock#Time event need to be used:
https://www.letscontrolit.com/wiki/inde ... .29_events

xury
Normal user
Posts: 44
Joined: 02 Apr 2018, 12:54

Re: sunrise/sunset to be used in rule

#10 Post by xury » 04 Jul 2018, 22:17

Perhaps that way:

Code: Select all

on Clock#Time=All,%sunrise% do
 if <test>
   <action>
   <action>
 endif
endon

TungstenE2
Normal user
Posts: 119
Joined: 03 Apr 2018, 21:46

Re: sunrise/sunset to be used in rule

#11 Post by TungstenE2 » 06 Jul 2018, 12:45

this is working great! thx!

Code: Select all

 On Clock#Time=All,%sunrise% do 
   <action>                               
endon

That makes it possible to do something at sunrise or sunset and also start a timer to do something at those moments + N seconds.

Code: Select all

//at sunrise time set timer1 for 1 hour
On Clock#Time=All,%sunrise% do 
        timerSet,1,3600                               
endon



//When Timer1 expires, <action>
 On Rules#Timer=1 do  
    <action>
 endon
 
 
 //at sunset set timer2 for 0,5 hour
On Clock#Time=All,%sunset% do 
        timerSet,2,1800                               
endon



//When Timer2 expires,  <action>
 On Rules#Timer=2 do  
    <action>
 endon

reliable
Normal user
Posts: 2
Joined: 09 Nov 2018, 10:56

Re: sunrise/sunset to be used in rule

#12 Post by reliable » 09 Nov 2018, 11:00

Hey.
I would like to use the state of sunrise or sunset when reloading ESP.
I write this rule:

Code: Select all

On System#Wake do
  if[Clock#Time=All,%sunrise%]=1
    TaskValueSet 4,3,0
  endif
endon
On System#Wake do
  if[Clock#Time=All,%sunset%]=1
    TaskValueSet 4,3,1
  endif
endon
but it does not work.
Tell me how to write the rules correctly?

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

Re: sunrise/sunset to be used in rule

#13 Post by grovkillen » 09 Nov 2018, 12:24

Try this one instead:

Code: Select all

On Time#Initialized do
  if %systime%>%sunrise% and %systime%<%sunset%
    TaskValueSet,4,3,0
   else
    TaskValueSet,4,3,1
  endif
endon
Just as an example. I really think it would be unique if you have the system booted at the exact minute of either sunset or sunrise...

Or if you want the rule to check each minute:

Code: Select all

On Clock#Time=All,%sunrise% do
    TaskValueSet 4,3,0
endon

On Clock#Time=All,%sunset% do
    TaskValueSet 4,3,1
endon
I think that last rule should work.. haven't tested it myself though.
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:

reliable
Normal user
Posts: 2
Joined: 09 Nov 2018, 10:56

Re: sunrise/sunset to be used in rule

#14 Post by reliable » 10 Nov 2018, 11:26

Thanks for the help. It really works as I need!

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

Re: sunrise/sunset to be used in rule

#15 Post by grovkillen » 10 Nov 2018, 11:42

Great, thanks for the feedback.
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:

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests