Activating and deactivating pins according to time of day

Totally new to the electric imp,
I am trying to make a timer function for a project.
I want to activate pin2 between 09:00 and 21:00
And I want to activate pin9 from 09:00 to 09:10, 13:00 to 13:10, 17:00 to 17:10 and 21:00 to 21:10.

I wish to activate both timers using a URL
Any suggestions or tips are much appreciated


The time() function will return the current timestamp, which you can use to calculate how far off those times are.

Once you know how far away the times are, you could use imp.wakeup() or server.sleepfor() depending on power needs (i.e. if your imp is plugged in, or running on batteries).

Be aware that the time() function returns UTC, which is probably different from your local time. The server logs appear to display in local time, but that is apparently browser magic using your browser locale, and it is not available to the imp.

You can either add the local time offset in code, or (much more complicated) call a service to find your location then use that to find your local time. Daylight saving is another complication, and you must plan whether you will just tweak an offset in code for these factors, or provide an interface to display and adjust the local time.

I made an example on how to use timezonedb, I am using this to offset the time in my IMP projects. :slight_smile: