Widget to set a time DURATION (not a particular point it time)

I have an idea - A duration timer widget. I know I can implement something like this with sliders, and other people have done it with simpletimer, but what about something like “Run fan for X minutes” which might just be a button that automatically turns itself off? Or even a widget that allows you to set a time not as a time of day, but a time in duration of seconds, minutes, hours, days, etc? Which would then either report to the hardware a UNIX time value of when the timer will time out, or just a number of milliseconds or seconds?

6 Likes

I think that such widget would very useful for diferent projects.
I need such widget.

I know this is reaaaally old topic but i searched the forum before this reply. (Yes, i did it :smiley: )

I control some relay with blynk and i want to save runtime for this relay. If pin goes high, timer starts to count. else pauses counting.

I need some idea about that. If possible, widget :stuck_out_tongue:

Thanks

You’d do this in code on the device that is controlling the relay.

When your relay is activated, grab the value of current millis. When the relay is deactivated take a note of the millis again. Deducting one from the other will give you the relay activation duration in milliseconds.

Depending on what sort of accuracy you’re looking for, you can then convert this into seconds, or minutes, or hours and add it to your running total of activation time.

You should use virtual pins to switch the relay, rather than doing direct pin manipulation from the app.

Pete.

1 Like

Thank you Pete. I am not familiar with millis function. I need to learn something about millis on long term runtimes.

Assuming that you’re using some sort of Arduino or ESP/ModeMCU device then it’s pretty simple and a bit of googling will give you some example code.
Basically, when the MCU boots it starts incrementing the internal millis counter - once every millisecond.
Because of the way that millis works, it resets to zero every 49 days, because the unsigned long variable used to store the counter overflows.

If that’s going to cause you an issue then an alternative is to use the RTC widget and grab the time at activation and deactivation of your relay. You’ll need to do your own calculations to turn the results into elapsed seconds (if that’s what you want).

Either way, you’ll find some examples with google and if you get stuck then come back with your efforts to date and ask for a bit of help.

Pete.

Thank you for the reply. I think RTC is better for me. I am logging data for a year. i am using ESP8266-01 now. That mean i need to change this to provide more pins for my project.

You explained great. I will do that after ordering new IC and modules.

Thank you

1 Like

Take a look at the Wemos D1 Mini, or if you need more pins then the NodeMCU v1 or higher.

Pete.

I also miss this functionality.
I think the current timer widget could be extended by the countdown function switch (to switch the functionality from manual “start_at-stop_at” to “stop_in”).
As a bonus, each tap on the timer would add the specified increment to the countdown
(same as the generic android clock - timer).

OR,
the push button widget could be extended by “keep pressed for X secs”.