Page 1 of 1

Virtual sensor for duration/time

Posted: Wednesday 09 May 2018 10:43
by jeroenb42
I am looking for a virtual sensor which can track duration/time. I want to track how long certain devices are on/in use. I have implemented a way to test whether these devices are on in another sensor and I would like to record how long these devices are on each day. I have been able to implement this by creating a dummy text sensor and every minute a script runs to check on the devices needed and updates these text sensors. It works but the two main drawback are that the log is useless and that you cannot easily compare it to a value (unless parsing it). It shows an update every minute the device is on but I would rather see a line graph which shows an increase when the device is on (time on is increasing) and a flat line if it isn't.
I know, you check this on the original device but I would like to create an alert for example if my heater is on for more than 1 hour when the temperature outside is greater than x or send an alert when minecraft has been played for more than x hours/minutes etc

Re: Virtual sensor for duration/time

Posted: Wednesday 09 May 2018 22:28
by freijn
What about this:

Increment a counter on the every minute check.

Re: Virtual sensor for duration/time

Posted: Thursday 10 May 2018 20:23
by Denny64
I think this is what you're looking for.

viewtopic.php?f=61&t=18848

It works great.