Time how much a device is ON  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

16pxdesign
Posts: 3
Joined: Friday 03 May 2019 2:48
Target OS: -
Domoticz version:
Contact:

Time how much a device is ON

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
16pxdesign
Posts: 3
Joined: Friday 03 May 2019 2:48
Target OS: -
Domoticz version:
Contact:

Re: Time how much a device is ON

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
16pxdesign
Posts: 3
Joined: Friday 03 May 2019 2:48
Target OS: -
Domoticz version:
Contact:

Re: Time how much a device is ON

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Time how much a device is ON

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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
edit device.png (51.72 KiB) Viewed 5495 times
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Time how much a device is ON

Post by felix63 »

Works, thanks. But I am still completely baffled by (incremental) counters.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post by waaren »

felix63 wrote:Works, thanks. But I am still completely baffled by (incremental) counters.
Do you have specific questions on how they work?




Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Time how much a device is ON

Post 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&param=udevice&idx=IDX&nvalue=0&svalue=1
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Lostnode
Posts: 2
Joined: Tuesday 18 May 2021 18:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time how much a device is ON

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Time how much a device is ON

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Lostnode
Posts: 2
Joined: Tuesday 18 May 2021 18:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time how much a device is ON  [Solved]

Post 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!
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Time how much a device is ON

Post by Tarzan737 »

Is it possible to get this in Minutes or Hours?
Zenek1961
Posts: 7
Joined: Monday 05 April 2021 16:46
Target OS: -
Domoticz version:
Contact:

Re: Time how much a device is ON

Post by Zenek1961 »

Is it possible to get this in Minutes or Hours?
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Time how much a device is ON

Post by Treve »

FYI: Waaren will never answer again, he passed away.
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Zenek1961
Posts: 7
Joined: Monday 05 April 2021 16:46
Target OS: -
Domoticz version:
Contact:

Re: Time how much a device is ON

Post by Zenek1961 »

maybe anybody other knows?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Time how much a device is ON

Post 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..... :oops:
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: habahabahaba and 1 guest