Page 1 of 1

Washing machine cost after running a load

Posted: Thursday 30 April 2020 13:59
by Ragdag
I've created a Washing Machine done DzVents script and with the help of waaren also got a beautiful PushOver notification when it's done running

The script senses that a load has started and sets a variable that the washing machine in use, when the power usage is below 6 Watt it will send a PushOver notification. So far so good :)

What I would like to add is a way to include the energie cost of that run but haven't figured out how to do that. I'm using a FIBARO System FGWPE/F Wall Plug Gen5+ to monitor power usage.

The idea is likely that I will need to capture the kWh when a load starts and the kWh when a load is finished and calculate the difference and the cost.

Any pointers would be really welcome, also any feedback on the current script is also welcome as I'm really novice in this.

Current script

Code: Select all

local scriptVar = 'Wasmachine'

return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },
        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        --level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },
    
    data = 
    {
       WasmachineTimeout = { initial = 1 },
       WasmachineInUse = { initial = 0 },
    },

    execute = function(domoticz, item)
    
        if item.isHTTPResponse then
            domoticz.log(item.data,domoticz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            domoticz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['User1'] = { ['key'] = 'aaaaaaaaaaaaaaaaaaaaaaaaa' },
            ['User2'] = { ['key'] = 'bbbbbbbbbbbbbbbbbbbbbbbbbbb'},
            ['Familie'] = { ['key'] = 'ccccccccccccccccccccccccccccccc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'dddddddddddddddddddddd' },
            ['Huis'] = { ['token'] = 'eeeeeeeeeeeeeeeeeeeeee' },
            ['Test'] = { ['token'] = 'ffffffffffffffffffffffffffff' },
            ['Was'] = { ['token'] = 'ggggggggggggggggggggggggg' },
        }

        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 6.0
        local WasmachineStartUsage = 10.0
        
        if (WasmachineUsage.actualWatt >= WasmachineStartUsage) and (domoticz.data.WasmachineInUse == 0) then
            domoticz.data.WasmachineInUse = 1
            domoticz.log("Setting Wasmachine in use to yes", domoticz.LOG_INFO)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end

        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) and (domoticz.data.WasmachineTimeout == 0) then
            domoticz.data.WasmachineTimeout = 1
            domoticz.log("Reseting counter, not done yet.", domoticz.LOG_DEBUG)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end
        
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
                domoticz.log(WasmachineUsage.actualWatt .. ' Watt usage, below standby usage, timout minus 1', domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.log(''.. WasmachineUsage.actualWatt .. ' Watt verbruik, dus is klaar', domoticz.LOG_INFO)
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                pushover(PushoverUsers.Familie, PushoverApps.Was, 'Was', 'De was is klaar.', 0, 'magic' )
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            end
        end
    end
}

Re: Washing machine cost after running a load

Posted: Thursday 30 April 2020 14:19
by waaren
Ragdag wrote: Thursday 30 April 2020 13:59 What I would like to add is a way to include the energie cost of that run but haven't figured out how to do that. I'm using a FIBARO System FGWPE/F Wall Plug Gen5+ to monitor power usage.
what is the devicetype / subtype of device 275 ? (as seen on the devices tab)

Re: Washing machine cost after running a load  [Solved]

Posted: Thursday 30 April 2020 14:44
by Ragdag
waaren wrote: Thursday 30 April 2020 14:19
Ragdag wrote: Thursday 30 April 2020 13:59 What I would like to add is a way to include the energie cost of that run but haven't figured out how to do that. I'm using a FIBARO System FGWPE/F Wall Plug Gen5+ to monitor power usage.
what is the devicetype / subtype of device 275 ? (as seen on the devices tab)
It is a kWh, Electricity (instant and counter)
https://www.domoticz.com/wiki/DzVents:_ ... counter.29

I think I figured it out already, I've added to persistent variables to the script:

Code: Select all

    data = 
    {
       WasmachineTimeout = { initial = 1 },
       WasmachineInUse = { initial = 0 },
       WasmachineStartkWh = { initial = 0 },
       wasmachineEndkWh = { initial = 0 },
    },
Then when I register the washing machine in use I register the domoticz.data.WasmachineStartkWh = WasmachineUsage.WhTotal if it is finished I do the same but then for the domoticz.data.wasmachineEndkWh = WasmachineUsage.WhTotal
After that it is just a simple formula WasmachineCost = (wasmachineEndkWh - WasmachineStartkWh) * 0.21 which should give me the rough cost, I hope.

The total script will be this.

Code: Select all

local scriptVar = 'Wasmachine'

return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },
        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },
    
    data = 
    {
        WasmachineTimeout = { initial = 1 },
        WasmachineInUse = { initial = 0 },
        WasmachineStartkWh = { initial = 0 },
        wasmachineEndkWh = { initial = 0 },
    },

    execute = function(domoticz, item)
    
        if item.isHTTPResponse then
            domoticz.log(item.data,domoticz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            domoticz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['User1'] = { ['key'] = 'aa' },
            ['User2'] = { ['key'] = 'bb'},
            ['Familie'] = { ['key'] = 'cc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'dd' },
            ['Huis'] = { ['token'] = 'ee' },
            ['Test'] = { ['token'] = 'ff' },
            ['Was'] = { ['token'] = 'gg' },
        }

        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 6.0
        local WasmachineStartUsage = 10.0
        local WasmachineCost
        
        if (WasmachineUsage.actualWatt >= WasmachineStartUsage) and (domoticz.data.WasmachineInUse == 0) then
            domoticz.data.WasmachineStartkWh = WasmachineUsage.WhTotal
            domoticz.data.WasmachineInUse = 1
            domoticz.log("Setting Wasmachine in use to yes", domoticz.LOG_INFO)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end

        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) and (domoticz.data.WasmachineTimeout == 0) then
            domoticz.data.WasmachineTimeout = 1
            domoticz.log("Reseting counter, not done yet.", domoticz.LOG_DEBUG)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end
        
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
                domoticz.log(WasmachineUsage.actualWatt .. ' Watt usage, below standby usage, timout minus 1', domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.log(''.. WasmachineUsage.actualWatt .. ' Watt verbruik, dus is klaar', domoticz.LOG_INFO)
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                domoticz.data.wasmachineEndkWh = WasmachineUsage.WhTotal
                WasmachineCost = (domoticz.data.wasmachineEndkWh - domoticz.data.WasmachineStartkWh) / 1000 * 0.2251 
                pushover(PushoverUsers.Familie, PushoverApps.Was, 'Was', 'De was is klaar.\nKosten: €' .. domoticz.utils.round(WasmachineCost, 2), 0, 'magic' )
                domoticz.log('Start kWh = ' .. domoticz.data.WasmachineStartkWh, domoticz.LOG_DEBUG)
                domoticz.log('End kWh = ' .. domoticz.data.wasmachineEndkWh, domoticz.LOG_DEBUG)                
                domoticz.log('Washing cost = €' .. domoticz.utils.round(WasmachineCost, 2), domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            end
        end
    end
}

Re: Washing machine cost after running a load

Posted: Thursday 30 April 2020 15:49
by Ragdag
Right now I have hard coded the price of energie in in the formula, is there a way to get that out of the Domoticz Settings?

Re: Washing machine cost after running a load

Posted: Thursday 30 April 2020 16:08
by waaren
Ragdag wrote: Thursday 30 April 2020 15:49 Right now I have hard coded the price of energie in in the formula, is there a way to get that out of the Domoticz Settings?
Yes by calling your
http://<domoticz_ip:domoticz:port>/json.htm?type=settings

you will get a HTTPResponse (json) like below (left out settings not relevant for this question)

Code: Select all

{
"AcceptNewHardware": 1,
"CostEnergy": "0.2149",
"CostEnergyR1": "0.0800",
"CostEnergyR2": "0.0800",
"CostEnergyT2": "0.2149",
"CostGas": "0.6218",
"CostWater": "1.6473",
"status": "OK",
"title": "settings"
}
Up to you if you want to get this cost this way. (Probably it only changes once a year tops)

Re: Washing machine cost after running a load

Posted: Thursday 30 April 2020 19:32
by Ragdag
Current script setup works as a charm.
Image

waaren, thank you again for your support!

Re: Washing machine cost after running a load

Posted: Saturday 02 May 2020 9:16
by krizzz
Can you post the whole script with the costs coming from the domoticz json call? Thanks!


Verzonden vanaf mijn iPhone met Tapatalk

Re: Washing machine cost after running a load

Posted: Saturday 02 May 2020 9:26
by Ragdag
krizzz wrote: Saturday 02 May 2020 9:16 Can you post the whole script with the costs coming from the domoticz json call? Thanks!


Verzonden vanaf mijn iPhone met Tapatalk
I did not integrate that yet.
This is the entire script, did change the utils.round to utils.numdecimals because otherwise 0.20 cents would be displayed as 0.2

Code: Select all

local scriptVar = 'Wasmachine'

return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },
        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },
    
    data = 
    {
        WasmachineTimeout = { initial = 1 },
        WasmachineInUse = { initial = 0 },
        WasmachineStartkWh = { initial = 0 },
        wasmachineEndkWh = { initial = 0 },
    },

    execute = function(domoticz, item)
    
        if item.isHTTPResponse then
            domoticz.log(item.data,domoticz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            domoticz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['User1'] = { ['key'] = 'aaa' },
            ['User2'] = { ['key'] = 'bbb'},
            ['Familie'] = { ['key'] = 'ccc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'ddd' },
            ['Huis'] = { ['token'] = 'eee' },
            ['Test'] = { ['token'] = 'fff' },
            ['Was'] = { ['token'] = 'ggg' },
        }

        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 6.0
        local WasmachineStartUsage = 10.0
        local WasmachineCost
        
        if (WasmachineUsage.actualWatt >= WasmachineStartUsage) and (domoticz.data.WasmachineInUse == 0) then
            domoticz.data.WasmachineStartkWh = WasmachineUsage.WhTotal
            domoticz.data.WasmachineInUse = 1
            domoticz.log("Setting Wasmachine in use to yes", domoticz.LOG_INFO)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end

        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) and (domoticz.data.WasmachineTimeout == 0) then
            domoticz.data.WasmachineTimeout = 1
            domoticz.log("Reseting counter, not done yet.", domoticz.LOG_DEBUG)
            domoticz.log("Timeout = " .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
        end
        
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
                domoticz.log(WasmachineUsage.actualWatt .. ' Watt usage, below standby usage, timout minus 1', domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.log(''.. WasmachineUsage.actualWatt .. ' Watt verbruik, dus is klaar', domoticz.LOG_INFO)
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                domoticz.data.wasmachineEndkWh = WasmachineUsage.WhTotal
                WasmachineCost = (domoticz.data.wasmachineEndkWh - domoticz.data.WasmachineStartkWh) / 1000 * 0.2251 
                pushover(PushoverUsers.Familie, PushoverApps.Was, 'Was', 'De was is klaar. 😘\nKosten: €' .. domoticz.utils.numDecimals(WasmachineCost, 2, 2), 0, 'magic' )
                domoticz.log('Start kWh = ' .. domoticz.data.WasmachineStartkWh, domoticz.LOG_DEBUG)
                domoticz.log('End kWh = ' .. domoticz.data.wasmachineEndkWh, domoticz.LOG_DEBUG)                
                domoticz.log('Washing cost = €' .. domoticz.utils.numDecimals(WasmachineCost, 2, 2), domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.WasmachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.WasmachineInUse, domoticz.LOG_DEBUG)
            end
        end
    end
}

Re: Washing machine cost after running a load

Posted: Wednesday 19 January 2022 14:30
by swejmansson
Found this topic and it was kind of what I was looking for. I re-used it, changed and updated it with some more features to fit my needs.
Thanks for sharing Ragdag :)

I posted my script here: viewtopic.php?f=72&t=37844