Stop a device if power too low

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

Moderator: leecollings

Post Reply
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Stop a device if power too low

Post by Patricen »

Hello,

I'm trying to set-up a script that would stop a device if the power consumption is below a minimum level for a few minutes (practically, I want to switch off the smart plug if the devices that are connected to it are in standby mode).

I'm trying to implement this using dzVents but no success as I do have issues extracting the actual power from the device (Zwave plug NAS-WR01Z Power plug 12A+).
Any clue?
Thanks!

Code: Select all

return 
{
    on =
    {
        devices = 
        {
            'Bureau-kWh Meter',
        },
    timer = {'Every 10 seconds'},
    },
    
    --data =
    --{
    --    lastupdated-- =
        --{
        --    initial = 0,
        --},
    --},

    logging = 
    {
        level = domoticz.LOG_DEBUG, --LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
        marker = 'Bureau-kWh Meter',
    },

    execute = function(dz, item)
        local Time = require('Time')
        local pwr = dz.devices('Bureau-kWh Meter').actualWatt
        local lowp
        local seuil = 8
        local lastupdated = Time
                
        if pwr > seuil then
			    dz.log('=========================consommation utilisation')
			    lowp = 0
			    lastupdated = Time(dz.time)
			    dz.log('=========================consommation utilisation' .. lastupdated)
                    -- on s'arrête là
            --return
        end
        if pwr < seuil  then
                dz.log('=========================basse consommation')
                if lowp == 1 then
                lastupdated = Time(dz.time)
                lowp = l
                dz.log('=========================basse consommation' .. lastupdated)
                return
        end
    end
end
}
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

So what is exactly your problem?
Do you get an error? Is the value pwr empty?
Is your device supporting the actualWatt function?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Stop a device if power too low

Post by Patricen »

Hello,
Below is the log. 700 is the id of the device, I've no idea if it supports actualWatt function, but for sure there is a power feedback on Domoticz control panel.

Code: Select all

2022-11-10 06:29:23.079 Status: dzVents: Info: Bureau-kWh Meter: ------ Start internal script: Stop bureau: Device: "Bureau-kWh Meter (OpenZWave)", Index: 700
2022-11-10 06:29:23.080 Status: dzVents: Info: Bureau-kWh Meter: =========================consommation utilisation
2022-11-10 06:29:23.080 Status: dzVents: Info: Bureau-kWh Meter: ------ Finished Stop bureau
2022-11-10 06:29:23.080 Error: dzVents: Error: (3.1.8) Bureau-kWh Meter: An error occurred when calling event handler Stop bureau
2022-11-10 06:29:23.080 Error: dzVents: Error: (3.1.8) Bureau-kWh Meter: /home/pi/domoticz/dzVents/runtime/Time.lua:28: bad argument #1 to 'match' (string expected, got table)
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

Read the docs about using time
https://www.domoticz.com/wiki/DzVents:_ ... ime_object

I think line

Code: Select all

local lastupdated = Time

should be

Code: Select all

local lastupdated = Time()
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 664
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Stop a device if power too low

Post by HvdW »

Maybe this post viewtopic.php?p=293865#p293865 is helpful for you.
If you have any questions: ask
Bugs bug me.
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Stop a device if power too low

Post by Patricen »

waltervl wrote: Wednesday 09 November 2022 12:31 So what is exactly your problem?
Do you get an error? Is the value pwr empty?
Is your device supporting the actualWatt function?
Do you have any idea about the way to find if a device supports actualWatt, or any other function?
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

Find the device type in the device widget and then look the device up in the DzVents documentation.
Also check the wiki with device examples https://www.domoticz.com/wiki/Dummy_for ... counter.29
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Stop a device if power too low

Post by Patricen »

waltervl wrote: Tuesday 15 November 2022 0:27 Find the device type in the device widget and then look the device up in the DzVents documentation.
Also check the wiki with device examples https://www.domoticz.com/wiki/Dummy_for ... counter.29
Ok it looks like the issue is related to
local pwr = dz.devices('Bureau-kWh Meter').WhActual
that leads to the following error : Error: dzVents: Error: (3.1.8) Bureau-kWh Meter: /home/pi/domoticz/dzVents/runtime/Time.lua:28: bad argument #1 to 'match' (string expected, got table)

as
dz.log('WhActual ' .. dz.devices('Bureau-kWh Meter').WhActual .. ' W')
gives the following log Status: dzVents: Info: Bureau-kWh Meter: WhActual 46.12 W

If I can go over the mismatch between string and table -that I do need help for-, I do figure out that there will be an issue afterwards when comparing a string to an integer, but this will be another story...
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

From the dzVents documentation
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Electric usage
actualWatt: Number. Current Watt usage.
WhActual: Number. Current Watt usage. (please use actualWatt)
So what if you use

Code: Select all

dz.devices('Bureau-kWh Meter').actualWatt
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

Additional, do you have more devices named 'Bureau-kWh Meter' as DzVents cannot handle multiple device with the same name. Device names should be unique!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Stop a device if power too low

Post by Patricen »

waltervl wrote: Wednesday 16 November 2022 16:34 Additional, do you have more devices named 'Bureau-kWh Meter' as DzVents cannot handle multiple device with the same name. Device names should be unique!
No, this is the only one
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Stop a device if power too low

Post by waltervl »

Did you try .actualWatt instead of .WhActual as advised by the documentation?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Stop a device if power too low

Post by Patricen »

Hello, yes, I tried, and I finally found out that the issue is coming from the pretty tricky time functions.
local Time = require('Time')
The issue is now clearer and I need to have power below x Watts for a "certain time" that I'm not able to code...
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest