I have a zigbee power plug (see photo).
I would like to monitor consumption with this.
Now I found a script here on the forum that does exactly what I want.
I have modified a few things to suit my need.
Unfortunately I can't get the script to work, I've been trying it out for days.
To test I use a 15 watt bulb.
Can someone please help me with this.
I have put the IDX numbers on the photo
Everything with (--this is new) I have adapted myself
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 = 'Machine kosten' -- 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,dz, item)
if item.isHTTPResponse then
domoticz.log(item.data,domoticz.LOG_DEBUG)
return
end
local Time = require('Time')
local MachineUsage = domoticz.devices(512) -- SETUP, This is the energy measuring device (see photo)
local MachinePricePerkWh = domoticz.CurrentPrice.value --this is new
--local MachinePricePerkWh = domoticz.variables('VariabelCurrentPrice').value -- SETUP, This is the price per kWh, replace with a fixed value if you prefer that
local MachineStandbyUsage = 1.0 -- SETUP, If below this power the Machine is in standby = finished, default value for Dishwasher/WashingMach/Dryer: 3/3/3
local MachineStartUsage = 3.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
local CurrentPrice --this is new
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('Machine is gestart!\nEn kWh kostar just nu ' .. MachinePricePerkWh ..' Euro') -- 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 (domoticzz.time == 'Between 23:00 and 07:00') or (dz.day == 'Saturday') or (dz.day == 'Sunday') then -- this is new
CurrentPrice = kwhPrijs ( 0.56565) -- Daltarief -- this is new
else CurrentPrice = kwhPrijs ( 0.6772) -- Normaal tarief --this is new
end --this is new
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('Machine is klaar!\n??:' .. MachineDuration .. 'min ?:' .. domoticz.utils.numDecimals(MachineUsed, 2, 2) .. 'kWh ?:' .. domoticz.utils.numDecimals(MachineCost, 2, 2) .. 'Euro')
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
}
Code: Select all
2023-01-17 21:32:00.325 Error: dzVents: Error: (3.1.8) Machine kosten: An error occurred when calling event handler Machine test
2023-01-17 21:32:00.325 Error: dzVents: Error: (3.1.8) Machine kosten: ...oticz/scripts/dzVents/generated_scripts/Machine test.lua:50: attempt to index a nil value (field 'CurrentPrice')Code: Select all
{
"ActTime" : 1673991319,
"AstrTwilightEnd" : "19:04",
"AstrTwilightStart" : "06:40",
"CivTwilightEnd" : "17:41",
"CivTwilightStart" : "08:02",
"DayLength" : "08:22",
"NautTwilightEnd" : "18:23",
"NautTwilightStart" : "07:20",
"ServerTime" : "2023-01-17 22:35:19",
"SunAtSouth" : "12:52",
"Sunrise" : "08:40",
"Sunset" : "17:03",
"app_version" : "2022.2",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CounterToday" : "0.080 kWh",
"CustomImage" : 0,
"Data" : "118.250 kWh",
"Description" : "",
"EnergyMeterMode" : "0",
"Favorite" : 0,
"HardwareDisabled" : false,
"HardwareID" : 26,
"HardwareName" : "Zigbee",
"HardwareType" : "Zigbee2MQTT",
"HardwareTypeVal" : 94,
"HaveTimeout" : false,
"ID" : "0x84fd27fffe3e26a4_power",
"LastUpdate" : "2023-01-17 22:35:16",
"Name" : "WCD smart (Power)",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" :
[
0
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : 1,
"SubType" : "kWh",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "current",
"Unit" : 63,
"Usage" : "13 Watt",
"Used" : 1,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "512"
}
],
"status" : "OK",
"title" : "Devices"
}