HowTo: Notification with duration, power usage and total cost when domestic machine starts/stops

Moderator: leecollings

Post Reply
swejmansson
Posts: 6
Joined: Saturday 10 March 2018 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

HowTo: Notification with duration, power usage and total cost when domestic machine starts/stops

Post by swejmansson »

Hi,

With the increasing electricity prices you get creative. Quite happy with what I have put together and would like to share it with you.
Hope you get some use of it :D

I wanted to get notification when a domestic machine like a dishwasher is finnished. The notification have to include duration, power used and also the cost for that specific wash. Searched and found a topic in this forum and based everything on that.
Link: viewtopic.php?f=59&t=32445&p=245629&hil ... g#p245629

How does it work?
- Machine started: When power exceeds "MachineStartUsage" a notification is sent containing the current price for electricity.
- Machine finnished: When power is less than "MachineStandbyUsage" for "MachineTimeout" minutes a new notification is sent. This one contains duration, used power and the total electricity cost.

What devices are needed?
- A smart plug or similar reporting the power being used by the machine.
- For cost calculation you need a device/variable with the current price.

How to setup?
Create one dzVents for each machine you have and copy the code into them.
In the script I have commented everything with "SETUP" that you need to setup.
You dont need any additional dummy switches or variables created for the script to work.
You will most likely need to do some tweeking with the parameters, I have added my values for dishwasher, washing machine and dryer.
Depending of what messaging service you use you might need to make some adjustments. I use Telegram.....

What the notifications will look like (sorry for the swedish):
Image



The dzVents script:

Code: Select all

-- This is a dzVents-script for monitoring a machine. It will send a notification when the machine has finnished its run. The message will include duration, powewr used and the cost.
-- I found the script on the domoticz forum, created by Ragdag and I wanted changed it to use Telegram and also added duration and some other features.
-- How to set it up? Find all comments with SETUP and update to fit your needs. For test, use a lamp as a load and set MachineStandbyUsage to 1 and MachineStartUsage to 3. Easier than starting and stopping your washer 😅
-- If my suggested parameters dont work with your machine, start the machine and look in domoticz to see the power used by the machine in the beginning of the cycle and in the end.
-- Regards, Jens Månsson

-- 220119, Version 1.0: Release, started of with https://www.domoticz.com/forum/viewtopic.php?f=59&t=32445&p=245629&hilit=ragdag#p245629 and added some features. Running fine for 1 week....

local scriptVar = 'Övervakning Diskmaskin'                                                 -- SETUP, Will be visable in the log, set it to something you can relate to like Dishwasher

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

    logging = 
    {
    level = domoticz.LOG_INFO,                                                       -- OPTIONAL, Set to LOG_DEBUG for debug info, set to LOG_INFO for minimal logs, Default = LOG_INFO
        marker = scriptVar,
    },
    
    data = 
    {
        MachineTimeout = { initial = 5 },                                            -- SETUP, Timeout value used in combination with stand by power to detect Machine is stopped, default value for Dishwasher/WashingMach/Dryer: 5/3/1
        MachineInUse = { initial = 0 },
        MachineStartkWh = { initial = 0 },
        MachineEndkWh = { initial = 0 },
        StartTime = { initial = 0 },
        StopTime = { initial = 0 },
    },

    execute = function(domoticz, item)
    
        if item.isHTTPResponse then
            domoticz.log(item.data,domoticz.LOG_DEBUG)
            return
        end

        local Time = require('Time')
        local MachineUsage = domoticz.devices('Plugg Maskin 3 energy')              -- SETUP, This is the energy measuring device
        local MachinePricePerkWh = domoticz.variables('VariabelCurrentPrice').value -- SETUP, This is the price per kWh, replace with a fixed value if you prefer that
        local MachineStandbyUsage = 3.0                                             -- SETUP, If below this power the Machine is in standby = finished, default value for Dishwasher/WashingMach/Dryer: 3/3/3
        local MachineStartUsage = 50.0                                              -- SETUP, If above this power the Machine us running, default value for Dishwasher/WashingMach/Dryer: 50/10/500
        local SendStartNotification = true                                          -- SETUP, If you like to get a notification when machine starts set to true
        local MachineCost
        local MachineUsed
        local MachineDuration
        local StartTimeCalc
        local StopTimeCalc

        if (MachineUsage.actualWatt >= MachineStartUsage) and (domoticz.data.MachineInUse == 0) then
            domoticz.data.MachineStartkWh = MachineUsage.WhTotal
            domoticz.data.StartTime = Time(domoticz.time.raw)
            domoticz.data.MachineInUse = 1
            if (SendStartNotification == true) then
                -- SETUP, Change the message into what ever you want.
                domoticz.notify('🍽️ Diskmaskinen är startad!\nEn kWh kostar just nu ' .. MachinePricePerkWh ..' öre')     -- SETUP, Change text to fit your needs
            end
            domoticz.log("------ The Machine was started " .. tostring(domoticz.data.StartTime.raw), domoticz.LOG_INFO)
            domoticz.log("Timeout value is set to " .. domoticz.data.MachineTimeout, domoticz.LOG_DEBUG)
        end

        if (MachineUsage.actualWatt >= MachineStandbyUsage) and (domoticz.data.MachineInUse == 1) and (domoticz.data.MachineTimeout == 0) then
            domoticz.data.MachineTimeout = 1
            domoticz.log("Reseting counter, not done yet.", domoticz.LOG_DEBUG)
            domoticz.log("Timeout value is now " .. domoticz.data.MachineTimeout, domoticz.LOG_DEBUG)
            domoticz.log("In use = " .. domoticz.data.MachineInUse, domoticz.LOG_DEBUG)
        end
        
        if (MachineUsage.actualWatt <= MachineStandbyUsage) and (domoticz.data.MachineInUse == 1) then
            if (domoticz.data.MachineTimeout > 0) then
                domoticz.data.MachineTimeout = domoticz.data.MachineTimeout - 1
                domoticz.log(MachineUsage.actualWatt .. ' Watt usage, below standby usage, timout minus 1', domoticz.LOG_DEBUG)
                domoticz.log('Timeout value is now ' .. domoticz.data.MachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.MachineInUse, domoticz.LOG_DEBUG)
            elseif (domoticz.data.MachineTimeout == 0) then
                domoticz.data.MachineInUse = 0
                domoticz.data.MachineTimeout = 1
                domoticz.data.MachineEndkWh = MachineUsage.WhTotal
                MachineCost = (domoticz.data.MachineEndkWh - domoticz.data.MachineStartkWh) / 100000 * MachinePricePerkWh   -- Deviding factor might need to be adjusted
                MachineUsed = (domoticz.data.MachineEndkWh - domoticz.data.MachineStartkWh) / 1000                          -- Deviding factor might need to be adjusted
                StartTimeCalc = domoticz.data.StartTime
                domoticz.data.StopTime = Time(domoticz.time.raw)
                StopTimeCalc = Time(domoticz.time.raw)
                MachineDuration =  StopTimeCalc.compare(StartTimeCalc).minutes

                -- SETUP, Change message, power unit and currency to fit your needs
                domoticz.notify('🍽️ Diskmaskinen är klar!\n⏱️:' .. MachineDuration .. 'min ⚡:' .. domoticz.utils.numDecimals(MachineUsed, 2, 2) .. 'kWh 💰:' .. domoticz.utils.numDecimals(MachineCost, 2, 2) .. 'kr')

                domoticz.log("------ The Machine was stopped " .. tostring(domoticz.data.StopTime.raw), domoticz.LOG_INFO)
                domoticz.log('Start time = ' .. tostring(StartTimeCalc.raw), domoticz.LOG_DEBUG)
                domoticz.log('Stop time = ' .. tostring(StopTimeCalc.raw), domoticz.LOG_DEBUG)
                domoticz.log('Start kWh = ' .. domoticz.data.MachineStartkWh, domoticz.LOG_DEBUG)
                domoticz.log('End kWh = ' .. domoticz.data.MachineEndkWh, domoticz.LOG_DEBUG)
                domoticz.log('Washing cost = ' .. domoticz.utils.numDecimals(MachineCost, 2, 2), domoticz.LOG_DEBUG)
                domoticz.log('Timeout = ' .. domoticz.data.MachineTimeout, domoticz.LOG_DEBUG)
                domoticz.log('In use = ' .. domoticz.data.MachineInUse, domoticz.LOG_DEBUG)
                
            end
        end
    
        if (domoticz.data.MachineInUse == 1) then
            domoticz.log('------ Machine is running', domoticz.LOG_INFO)
        else
            domoticz.log('------ Machine is NOT running', domoticz.LOG_INFO)
        end
    end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests