The problem on line 50 is, that you set to look to variable "currentprice".
But currentprice is set on line 86. This is to late.
The script is running from line 1 to the end. It doesn't search in the script where it can't find its information.
This part where the "CurrentPrice" is set, needs to be above line 50, before "local MachinePricePerkWh" is set
Code: Select all
if (domoticz.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 [code]
Have a look at what you set your CurrentPrice to.
kwhPrijs ( 0.56565) is not something you can use. It is not a value, it is text, but on line 50 you want a value.
Also my advice. Use domoticz.xxxx or dz.xxxx. Not both
Change this line in:
[code] execute = function(domoticz,dz, item)
to
Code: Select all
execute = function(domoticz, item)
and change all dz.xxxx to domoticz.xxxx
domoticz and dz are the same. only 1 is complety written out, the otherone is the short version.
choose 1 of these in your script, not both
Second advice. remove everything with CurrentPrice.
And change it to MachinePricePerkWh. No you have made a variable to set an other variable with the same setting
Not tested, but this is what i mean.
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, 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 --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
if (domoticz.time == 'Between 23:00 and 07:00') or (domoticz.day == 'Saturday') or (domoticz.day == 'Sunday') then -- this is new
MachinePricePerkWh = 0.56565 --kwhPrijs Daltarief -- this is new
else
MachinePricePerkWh = 0.6772 --kwhPrijs Normaal tarief --this is new
end
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 (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
}