Page 1 of 2
Time how much a device is ON
Posted: Friday 03 May 2019 2:52
by 16pxdesign
Hi, I want to achieve this effect using dzVents
https://www.domoticz.com/forum/viewtopic.php?t=18848
I don't know how to set time for this counter, there is no problem when the counter is just counter but when I change it to time version I have a problem. Can anybody help?
Re: Time how much a device is ON
Posted: Friday 03 May 2019 8:41
by waaren
16pxdesign wrote: ↑Friday 03 May 2019 2:52
Hi, I want to achieve this effect using dzVents
https://www.domoticz.com/forum/viewtopic.php?t=18848
I don't know how to set time for this counter, there is no problem when the counter is just counter but when I change it to time version I have a problem. Can anybody help?
Can you please explain in more detail what you try to achieve and what the problem is you face ? For me it's unclear from the above description and after reading the topic.
Re: Time how much a device is ON
Posted: Friday 03 May 2019 19:25
by 16pxdesign
Ok so I have dummy counter and I set the counter in Domoticz as time counter. When I try to use a method "updateCounter()" and pass any number it not change any state of this counter. This method works for the normal counter but doesn't want to work with a time counter. So my question is how I can set time counter values in dzVents
Re: Time how much a device is ON
Posted: Friday 03 May 2019 22:12
by waaren
16pxdesign wrote: ↑Friday 03 May 2019 19:25
Ok so I have dummy counter and I set the counter in Domoticz as time counter. When I try to use a method "updateCounter()" and pass any number it not change any state of this counter. This method works for the normal counter but doesn't want to work with a time counter. So my question is how I can set time counter values in dzVents
Ok understand now but have to disappoint you. It cannot be done from dzVents. In fact I asked the core developers some time ago how to update this from the API and no one could give me an answer. So either the developer that introduced this (maybe for future use) is no longer developing here or it is a left over from the past.
But if you tell what is it that you want to measure, I might be able to help using another solution than a time counter.
Re: Time how much a device is ON
Posted: Friday 03 May 2019 23:43
by 16pxdesign
OK, Good to know, thanks. I got 3 heaters but I need to know how long they work in minutes or hours. I know you got logs but it hard to read total time it been ON or OFF.
Re: Time how much a device is ON
Posted: Saturday 04 May 2019 19:38
by waaren
16pxdesign wrote: ↑Friday 03 May 2019 23:43
OK, Good to know, thanks. I got 3 heaters but I need to know how long they work in minutes or hours. I know you got logs but it hard to read total time it been ON or OFF.
How do you want to record the heaters on time ?
Could be stored in a domoticz variable, a counter device per heater, One or more text devices, stored in the description field of these heaters and probably in a couple of other ways.
Re: Time how much a device is ON
Posted: Friday 30 April 2021 16:38
by felix63
I have a similar use case. When a device is switched off I want to update a virtual device - (timer) counter so I can track the time the device has been on. In dzvents I tried but can't get it to work.
Re: Time how much a device is ON
Posted: Friday 30 April 2021 23:15
by waaren
felix63 wrote: ↑Friday 30 April 2021 16:38
I have a similar use case. When a device is switched off I want to update a virtual device - (timer) counter so I can track the time the device has been on. In dzvents I tried but can't get it to work.
Could look like below
Code: Select all
return
{
on =
{
devices =
{
1324, -- device for which you want to record the On time.
},
},
data =
{
lastOn = { initial = 0 },
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'timeKeeper',
},
execute = function(dz, item)
local secondsActive = 0
local iCounter = dz.devices('timeKeeper') -- define as virtual incremental counter
if item.active then
if dz.data.lastOn == 0 then dz.data.lastOn = os.time() end
return
else
if dz.data.lastOn == 0 then
secondsActive = os.time() - item.lastUpdate.dDate
else
secondsActive = os.time() - dz.data.lastOn
dz.data.lastOn = 0
end
iCounter.updateCounter(secondsActive)
end
end
}
Edit your incremental counter to look like.

- edit device.png (51.72 KiB) Viewed 5997 times
Re: Time how much a device is ON
Posted: Saturday 01 May 2021 1:05
by felix63
Works, thanks. But I am still completely baffled by (incremental) counters.
Re: Time how much a device is ON
Posted: Saturday 01 May 2021 7:58
by waaren
felix63 wrote:Works, thanks. But I am still completely baffled by (incremental) counters.
Do you have specific questions on how they work?
Re: Time how much a device is ON
Posted: Saturday 01 May 2021 10:57
by felix63
I am trying to find some info on:
- difference between counter, managed counter and incremental counter
- what is the function of counter type 'Time', and how to use it from a script. The following command for instance doesn't do anything on a counter of type time.
Code: Select all
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=1
Re: Time how much a device is ON
Posted: Saturday 01 May 2021 22:02
by waaren
felix63 wrote: ↑Saturday 01 May 2021 10:57
I am trying to find some info on:
- difference between counter, managed counter and incremental counter
counter: When you send something to the counter the existing value is replaced.
incremental counter: When you send something to this one the value is added to the existing value.
managed counter: counter without automatic history. You have to take care of the history yourself using API 's
- what is the function of counter type 'Time', and how to use it from a script. The following command for instance doesn't do anything on a counter of type time.
I asked the core developers months ago how to update this from the API and no one could give me an answer. So either the developer that introduced this (maybe for future use) is no longer developing here or it is a left over from the past.
No one stepped forward until now on how to use this. (if at all possible)
Re: Time how much a device is ON
Posted: Tuesday 18 May 2021 18:54
by Lostnode
Hi waaren,
I tried your code and it works for logging on-time for each event.
But what if you'd like a counter that records total time a device has been turned on over a longer period (accumulated time)?
Do you have an example of that as well?
Re: Time how much a device is ON
Posted: Tuesday 18 May 2021 22:36
by waaren
Lostnode wrote: ↑Tuesday 18 May 2021 18:54
I tried your code and it works for logging on-time for each event.
But what if you'd like a counter that records total time a device has been turned on over a longer period (accumulated time)?
Maybe I do not completely understand what you mean but if you used incremental counter as device type when creating the counter it should already do just that. If not please elaborate on your question.
Re: Time how much a device is ON [Solved]
Posted: Thursday 20 May 2021 18:50
by Lostnode
waaren wrote: ↑Tuesday 18 May 2021 22:36
Lostnode wrote: ↑Tuesday 18 May 2021 18:54
I tried your code and it works for logging on-time for each event.
But what if you'd like a counter that records total time a device has been turned on over a longer period (accumulated time)?
Maybe I do not completely understand what you mean but if you used incremental counter as device type when creating the counter it should already do just that. If not please elaborate on your question.
Hi, and thanks for replying. Sorry for not answering sooner.
Well, I learned something new today. Created a new counter but incremental instead. works fine!
Thanks!
Re: Time how much a device is ON
Posted: Monday 14 June 2021 22:03
by Tarzan737
Is it possible to get this in Minutes or Hours?
Re: Time how much a device is ON
Posted: Monday 06 June 2022 23:40
by Zenek1961
Is it possible to get this in Minutes or Hours?
Re: Time how much a device is ON
Posted: Tuesday 07 June 2022 6:33
by Treve
FYI: Waaren will never answer again, he passed away.
Re: Time how much a device is ON
Posted: Tuesday 07 June 2022 14:22
by Zenek1961
maybe anybody other knows?
Re: Time how much a device is ON
Posted: Tuesday 07 June 2022 15:33
by waltervl
Yes but you will have to modify the script to have it give minutes or hours to the counter instead of seconds (value SecondsActive).
Be aware you have to make it an integer so be careful with rounding. See
https://domoticz.com/forum/viewtopic.php?t=26512
Edit: Also a Counter divider value of 60 (for minutes) or 3600 (for hours) should work.....
