Trying to make an auto-adjusting light timer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Trying to make an auto-adjusting light timer

#1 Post by micsaund » 16 Jul 2018, 21:33

Hi all,

This is my first project using ESP Easy / Sonoff. My goal is to make a standalone lamp timer that will turn the light on at sunset (actually 1 hour earlier, but I haven't gotten that far). I could do this with Home Assistant or something else, but I'm trying to keep the timer a 'drop in' replacement for a regular old mechanical lamp timer, so would prefer no server required. The built-in button allows manual override.

As such, I flashed a Sonoff Basic with mega-20180615 and it works fine manually. I set DST/timezone offset so I see the correct local time on the "Main" tab and also enabled NTP.

However, using the following rule, the light never turns-on automatically at 'sunset'. I'm obviously missing something despite the exceptionally basic nature of what I'm trying to do. Any ideas?

Code: Select all

// =============
// Button overrride
// =============
on button#switch do
  if [button#switch]=1
   gpio,12,1
   gpio,13,0 // LED needs to be low when relay is closed to indicate power on.
  else
   gpio,12,0
   gpio,13,1 
  endif
endon 

// ==============
// Turn on at sunset
// ==============
On Clock#Time=All,%sunset% do
  gpio,12,1
  gpio,13,0
endon

// ===============
// Turn off at midnight
// ===============
on Clock#Time=All,00:00 do
  gpio,12,0
  gpio,13,1
endon
Thanks!
Mike

wim16
Normal user
Posts: 88
Joined: 01 May 2017, 20:35

Re: Trying to make an auto-adjusting light timer

#2 Post by wim16 » 16 Jul 2018, 21:55

I think %sunset% was introduced in 20180618.

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#3 Post by micsaund » 16 Jul 2018, 22:14

Well, that might explain it! Let me go try to find the newer version and try it out.

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#4 Post by micsaund » 17 Jul 2018, 00:24

OK, upgraded to mega-20180716 and will see if that works tonight!

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#5 Post by micsaund » 17 Jul 2018, 03:00

wim16 - that fixed it! I came home and the light was on :)

Now, to figure-out how to do "2 hours before %sunset%" since my house gets dark before sunset...

Thanks for the help!
Mike

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

Re: Trying to make an auto-adjusting light timer

#6 Post by grovkillen » 17 Jul 2018, 05:54

Right now it's not implemented (I think) but later you would use %sunset-120m% or %sunset-2h% but until then you can use a timer to achieve the same thing. When sunset happens you start a timer, when the timer expire you do your thing (turning lights off etc).
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:

wim16
Normal user
Posts: 88
Joined: 01 May 2017, 20:35

Re: Trying to make an auto-adjusting light timer

#7 Post by wim16 » 17 Jul 2018, 09:37

But that is for 'after sunset', not before.
I use a BH1750 Lux-meter to 'adjust the sunset'

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Trying to make an auto-adjusting light timer

#8 Post by Micha_he » 17 Jul 2018, 09:56

Maybe a workaround:

Set today at sunset a timer with e.g. 22h for tomorrow. The sunset only changes <1min for 24h.

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

Re: Trying to make an auto-adjusting light timer

#9 Post by grovkillen » 17 Jul 2018, 10:27

True, sorry! But @Micha_he suggests a solid workaround.
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:

wim16
Normal user
Posts: 88
Joined: 01 May 2017, 20:35

Re: Trying to make an auto-adjusting light timer

#10 Post by wim16 » 17 Jul 2018, 10:42

That's a nice workaround indeed. I did not know timers can be set for as long as 24 hours.

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#11 Post by micsaund » 17 Jul 2018, 18:17

Is %sunset% something that is set and usable any time after sunset (until sunrise), or is it a one-time event (specific to a hour:minute)?

I'm just trying to think of a power outage situation - would I be able to check %sunset% say, 3 hours after sunset, and know to turn the light on? Here in Florida, it's more common to have little power blips due to lightning storms than I'd prefer.

I'll try the 22 hour timer idea. That should work until the %sunset% - 2h is implemented. I guess if there was a power outage, the light would turn-on at sunset that first night and then the following nights, the 22 hour timer would take-over.

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

Re: Trying to make an auto-adjusting light timer

#12 Post by grovkillen » 17 Jul 2018, 19:12

Yes your suspicion is probably right. If you set up the rule that way. You can do a check every night at 01:00 (as an example) that set the timer for that next sunset (or rise).
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:

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#13 Post by micsaund » 17 Jul 2018, 23:06

To test, I just ran:

Code: Select all

On Clock#Time=All,%sunrise% do
  gpio,12,1
endon
It's before sunset, so if the sunrise variable was continuously available, I'd expect to see my light turn on. However, it did not, so I'm guessing that %sunrise%/%sunset% are "hour:minute" specific and not something that's queryable at any time. That makes recovering from power outages (in a self-contained EasyESP device) more difficult.

moebius
Normal user
Posts: 35
Joined: 22 May 2017, 19:36

Re: Trying to make an auto-adjusting light timer

#14 Post by moebius » 17 Jul 2018, 23:55

- just add another rule to turn the light on at a certain time
- a reboot also resets the internal clock - so after a power outage the esp needs an ntp server, which means you could turn on the light with a script running on your router or somewhere else in your network
- use a light sensor with an adjustable digital output for 60 cents (https://www.aliexpress.com/item/2PCS-Ph ... 32805.html)

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#15 Post by micsaund » 18 Jul 2018, 01:40

I just ordered a handful of those light sensors and will try them out.

However, my overall goal was a *standalone* timer that didn't need a server (router, Pi, etc.) and would be suitable for tech-incompetent in-laws, for example. Having to ensure that both the 'server' and the various 'outlets' are communicating is something I'd rather not deal with over the phone. If the outlets can simply join the wifi when available and begin working, that's the goal.

moebius
Normal user
Posts: 35
Joined: 22 May 2017, 19:36

Re: Trying to make an auto-adjusting light timer

#16 Post by moebius » 18 Jul 2018, 15:03

Having to ensure that both the 'server' and the various 'outlets' are communicating is something I'd rather not deal with
Providing the correct time to the outlets for any time based operation is some sort of communication
was a *standalone* timer
And how would you do that with the sonoff?
This functionality requires some rtc module (or dcf77,...) which is not part of sonoff devices.
simply join the wifi
Which would require some kind of wifi router, where you possibly could run the ntp server, scripts, etc

If you dont want / need communication between the devices, it is easier to buy a light with a brightness sensor.
Cause communication is the feature, a normal hardware device cant provide (eg you could publish the value from the light sensor to other devices, so that you would only need one sensor for n actors)

micsaund
New user
Posts: 9
Joined: 16 Jul 2018, 21:22

Re: Trying to make an auto-adjusting light timer

#17 Post by micsaund » 18 Jul 2018, 20:34

Sorry - by 'server' I meant another device running some kind of software that I have to install/maintain. I can use the in-law's router for wifi, but I don't want to be trying to run something on it (I'm sure it's the cheapest PoS router anyway). So far, using NTP on the Sonoff seems to work well enough and other than power outages, I think this auto-setting outlet is probably 'good enough' for their needs. For my own home system, where I'm hands-on, I plan to run HassIO or something and with that, I'll get more advanced in data retrieval/etc.

Thanks for the ideas everyone.

Mike

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

Re: Trying to make an auto-adjusting light timer

#18 Post by grovkillen » 19 Jul 2018, 10:14

As of the nightly released today we now support offset of the sunset and sunrise. It's explained here: https://www.letscontrolit.com/wiki/inde ... _Variables
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: Ahrefs [Bot] and 27 guests