Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule to set relay ON between sunset and sunrise after power loss on Time#Initialized. #2669

Closed
dmytrobabeshko opened this issue May 8, 2018 · 7 comments
Labels
enhancement Type - Enhancement that will be worked on

Comments

@dmytrobabeshko
Copy link

Hello,

I use Sonoff basic as automatic standalone day/night switch for street lightning using approach with Sunset/Sunrise for timers.
The problem that after power loss I need to set correct relay state. For example if power loss happened at night I need to understand whether it restored at night or at day to switch relay ON or OFF.
Is it possible to create Rule which will trigger between sunset and sunrise to switch relay On?

Thank you in advance!

@dmytrobabeshko dmytrobabeshko changed the title Rule to set relay ON between sunset and sunrise ешьу after power loss. Rule to set relay ON between sunset and sunrise after power loss on Time#Initialized. May 8, 2018
@curzon01
Copy link
Contributor

curzon01 commented May 8, 2018

If you set PowerOnState to default Sonoff will restore the last state after power loss automatically, no necessary to add something

@dmytrobabeshko
Copy link
Author

PowerOnState won't work as expected.
For example:
Sunrise 5:00
Sunset 20:00

  1. 5:00 Sunrise timer triggers - OFF
  2. 19:55 Power loss
  3. 20:05 Power restored - Last state OFF
    I need street lights ON during nighttime.

Or viseversa

  1. 20:00 Sunset timer triggers - ON
  2. 4:55 Power loss
  3. 5:30 Power restore - Last state ON
    No need in ON street lights during daytime.

The problem that we have several power loss/restore combinations and PowerOnState can't cover all of them.
Loss/Restore

Daytime/Daytime
Daytime/Nighttime
Nighttime/Nighttime
Nighttime/Daytime

@curzon01
Copy link
Contributor

curzon01 commented May 9, 2018

What you need is a retrigger on startup for all last non-trigger.

Well, as enhancements like that are more or less special expections and would be better handled by a third system. I don't think that all these exceptional user requirements can be handled by such small device in future (for your case the system needs to "remember" which trigger are already triggered), my suggestion for your need is a workaround: use a home system like Fhem which can handle retrigger of non-triggered events.

@ascillato
Copy link
Contributor

Hi,

Now, in rules there are the commands VAR1 to VAR5 and MEM1 to MEM5 to store temporary and permanent values. And then, you can use them as %var1% and %mem1% inside rules.

What about adding new values that report :

  • %time% : actual elapsed time since midnight in minutes
  • %sunrise% : sunrise in minutes
  • %sunset% : sunset in minutes
  • %uptime% : actual uptime in minutes

So, with those, we could make a rule like:

For example: If we want a light to be on from 20:00 to 8:00 and to be off from 8:00 to 20:00
So, 8 hr = 8 x 60 = 480 minutes, and 20 hr = 20 x 60 = 1200 minutes

Rule:

on Time#Initialized do backlog power1 off; event check=%time% endon
on event#check>1200 do power1 on endon
on event#check<480 do power1 on endon

What do you think?

@ascillato
Copy link
Contributor

@arendst what do you think?

@ascillato2 ascillato2 added the enhancement Type - Enhancement that will be worked on label Jun 11, 2018
@arendst
Copy link
Owner

arendst commented Jun 25, 2018

@ascillato Don't you think these time related values are already served by the the timer options already available? This seems to duplicate the timer functionality.

@ascillato
Copy link
Contributor

Hi

The timers will be excecuted as a trigger, while %time% will be as a conditional.

So, for the issue explained by dmitrybabeshko, if the sonoff is not powered while the timer should trigger, then, when it is powered up, it will not trigger the output or rule that was intended.

With a rule with %time% at Time#Initialized for example, the condition of reaching or passing that trigger time can be checked, so the output or rule can be trigger and it is not going to be missed.

I think that adding this conditions to the actual timers will make them more complex with more options and with more memory/flash use. That's why, I think that having some extra internal time variables exposed to rules will be more flexible and less code hungry.

Another use, besides turning lights at night and do not miss it if the energy was down during the trigger time, can be change the behavior of the sonoff in different hours, also without missing the trigger time.

arendst added a commit that referenced this issue Jun 26, 2018
6.0.0a
* Add time in minutes to rule Time#Initialized, Time#set and Time#Minute
(#2669)
* Add rule variables %time% for minutes since midnight, %uptime%,
%sunrise% and %sunset% giving time in minutes (#2669)
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 7, 2018
6.0.0a
* Add time in minutes to rule Time#Initialized, Time#set and Time#Minute
(arendst#2669)
* Add rule variables %time% for minutes since midnight, %uptime%,
%sunrise% and %sunset% giving time in minutes (arendst#2669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

No branches or pull requests

5 participants