Energy Consumption based activites Topic is solved

Moderator: leecollings

Post Reply
FabianHD
Posts: 5
Joined: Wednesday 06 March 2019 19:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Energy Consumption based activites

Post by FabianHD »

Hello everyone,

After reading https://www.domoticz.com/wiki/Capturing ... ua_Scripts, I am trying to implement an energy based action in Lua, but unfortunately I struggle to get the right commands for the current and the duration into Lua.

My idea behind is the following:
Once device (='Dishwasher') is turned on, it should check the used current, if this is lower than value x for a certain period of time, it should turn the device off again, at the moment, the only thing I have is the following:

Code: Select all

commandArray = {}
if (devicechanged['Dishwasher'] == 'On') then
        commandArray['Dishwasher']='Off'

end
return commandArray
Thanks for your support
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Energy Consumption based activites

Post by EddyG »

In the dzVents section are several scripts present.
It depends with what you measure the current and with what you want something to switch
I have a neo coolcam switch which also measures the currrent.
FabianHD
Posts: 5
Joined: Wednesday 06 March 2019 19:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy Consumption based activites

Post by FabianHD »

thanks for your feedback, I am using a Sonoff Pow to measure my power with.

Describing in simple words:

If Dishwasher is turned on and Energy-Consumption Dishwasher is < 10 Watt for more than 10 min then
Turnoff Dishwasher
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Energy Consumption based activites

Post by EddyG »

Here are some scripts: viewtopic.php?f=72&t=23798
I have a modified one for an Neo coolcam plug, which is a switch (plug) and a power measuring device. So 2 in 1.
If you use the Sonoff the same way you could use the script below, with thanks to the guys in the above link.

Code: Select all

local USAGE_DEVICES = {
        ['Wasmachine kWh Meter'] = 'Wasmachine',        -- You need to have a inline wall plug that measures energy,
        ['Wasdroger kWh Meter'] = 'Wasdroger',          -- here you make the link between the energy device and the wall plug.
        ['Airco kWh Meter'] = 'Airco'                   -- Adjust to your needs. Between every line you need to add a ",".
}

local USAGE_SwitchTimeOutMinutes = {
        ['Wasmachine'] = 5,     -- Here you define how long no power is used per device.
        ['Wasdroger'] = 6,      -- The period is in minutes.
        ['Airco'] = 3           -- Adjust to your needs. Between every line you need to add a ",".
}

local USAGE_MaxWatt = {
        ['Wasmachine'] = 5,     -- Here you define the maximum amount of power a device uses when it is in standby.
        ['Wasdroger'] = 5,      -- Some devices uses a little amount of power. Test it and put here the slightly higher power usage.
        ['Airco'] = 5           -- Adjust to your needs. Between every line you need to add a ",".
}

local USAGE_Notify = {
        ['Wasmachine'] = 'Yes', -- In some cases you want to be notified when a device is turned on and off.
        ['Wasdroger'] = 'No',   -- Adjust to your needs. Between every line you need to add a ",".
        ['Airco'] = 'Yes'
}

return {
        active = true,
--      active = false,

        logging = {
                level = domoticz.LOG_INFO,      -- Uncomment to override the dzVents global logging setting
                marker = 'POW'
        },
        on = {
                devices = {                     -- Make sure that the devices are the same as above
                        'Wasmachine',
                        'Wasmachine kWh Meter',
                        'Wasdroger',
                        'Wasdroger kWh Meter',
                        'Airco',
                        'Airco kWh Meter'
                },
        },
        data = {                                -- use exact device names to match USAGE_DEVICES
                ['Wasmachine kWh Meter'] = { history = true, maxMinutes = 6 },
                ['Wasdroger kWh Meter'] = { history = true, maxMinutes = 10 },
                ['Airco kWh Meter'] = { history = true, maxMinutes = 10 }
        },

        execute = function(dz, device)
--              local debug = true
                local debug = false

                if (USAGE_DEVICES[device.name] ~= nil) then
                        -- we have a usage sensor here
                        local switch = dz.devices(USAGE_DEVICES[device.name])
                        local history = dz.data[device.name]
                        local timeout = USAGE_SwitchTimeOutMinutes[USAGE_DEVICES[device.name]]
                        local watt = USAGE_MaxWatt[USAGE_DEVICES[device.name]]
                        if debug then
                                dz.log(switch.name .. " - Status: " .. switch.state .. " - Age: " .. switch.lastUpdate.minutesAgo .. " minutes")
                                dz.log("timeout = " .. timeout .. " - maxwatt = " .. watt .. " - current power: " ..device.usage .. " - Average: " .. dz.utils.round(history.avg()))
                        end
                        if switch.state == "On" then
                                history.add(device.usage)
                                if (history.avg() <= watt and switch.lastUpdate.minutesAgo >= timeout) then
                                        dz.log("Switching " .. switch.name .. "Off")
                                        switch.switchOff().checkFirst()
                                        dz.data[device.name].reset()
                                end
                        end
                else
                        -- device is a switch
                        local notify = USAGE_Notify[device.name]
                        if debug then
                                dz.log(device.name .. " notify = " .. notify)
                        end
                        if (device.state == "On" and notify == "Yes") then
                                dz.notify(
                                        "ACTIVATE",
                                        device.name .. " activated#I let you know when device " .. device.name .. " is turned off",
                                        dz.PRIORITY_NORMAL,
                                        dz.SOUND_SIREN,
                                        "",
                                        { dz.NSS_HTTP, dz.NSS_GOOGLE_CLOUD_MESSAGING }
                                )
                        elseif (notify == "Yes") then
                                dz.notify(
                                        "DEACTIVATED",
                                        device.name .. " is klaar.",
                                        dz.PRIORITY_HIGH,
                                        dz.SOUND_INTERMISSION,
                                        "",
                                        { dz.NSS_HTTP, dz.NSS_GOOGLE_CLOUD_MESSAGING }
                                )
                        end
                end
        end
}
Last edited by EddyG on Tuesday 12 March 2019 18:46, edited 1 time in total.
FabianHD
Posts: 5
Joined: Wednesday 06 March 2019 19:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy Consumption based activites

Post by FabianHD »

thank you very much, your scrip looks really great and it works perfectly!

One question for further understanding:

Code: Select all

local USAGE_SwitchTimeOutMinutes = {
        ['Wasmachine'] = 5,     -- Here you define how long no power is used per device.
        ['Wasdroger'] = 6,      -- The period is in minutes.
        ['Airco'] = 3           -- Adjust to your needs. Between every line you need to add a ",".
        
        

Code: Select all

        data = {                                -- use exact device names to match USAGE_DEVICES
                ['Wasmachine kWh Meter'] = { history = true, maxMinutes = 6 },
                ['Wasdroger kWh Meter'] = { history = true, maxMinutes = 10 },
                ['Airco kWh Meter'] = { history = true, maxMinutes = 10 }
        
What is the difference between both time periods?
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: Energy Consumption based activites

Post by felix63 »

The time period defined in USAGE_SwitchTimeOutMinutes is the amount of time that a machine has to report a power usage below the level defined in USAGE_MaxWatt. The time specified as maxMinutes in the data clause specifies the amount of historical data on kWh that needs to be kept. In order for the script to work the USAGE_SwitchTimeOutMinutes should be lower than maxMinutes. This because the script uses the historical data to determine the average usages.
FabianHD
Posts: 5
Joined: Wednesday 06 March 2019 19:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Energy Consumption based activites

Post by FabianHD »

thank you, now I fully understood the script!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest