Piacco wrote: Tuesday 11 February 2020 20:05
print("Usage boilermeter" .. boilermeter), gives an error
Code: Select all
print("Usage boilermeter" .. boilermeter)
Log_Usage.JPG
Changed some logic in below script. Best to start with new virtual devices and another script name to prevent mixup with old data.
Also shows how to get information to the log.
Code: Select all
return
{
on =
{
timer =
{
'every minute',
},
},
data =
{
usage = { initial = 0 },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = "heatpump"
},
execute = function(dz)
--- Changes below this line
local houseActive = dz.devices('stateSwitch').state == 'On' -- change to name of your state switch
local power = dz.devices('Power') -- change to name of your P1 meter
local usage = power.usage1 + power.usage2
local housemeter = dz.devices('house') -- define as counter inremental
local boilermeter = dz.devices('boiler') -- define as counter inremental
-- No changes below this line
if houseActive and dz.data.usage ~= 0 then
housemeter.incrementCounter(usage - dz.data.usage)
dz.log('usage ' .. housemeter.name ..': ' .. (usage - dz.data.usage),dz.log_DEBUG)
boilermeter.incrementCounter(0)
elseif dz.data.usage ~= 0 then
boilermeter.incrementCounter(usage - dz.data.usage)
dz.log('usage ' .. boilermeter.name ..': ' .. (usage - dz.data.usage),dz.log_DEBUG)
housemeter.incrementCounter(0)
end
dz.data.usage = usage
end
}
When not yet familiar with dzVents please start with reading
Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki