I have created my first script. My goal is to use value's of my P1 meter and my Solar meter to calculate what I am using in house as kWh.
Basically the script is running OK, but for some reason.. when the clock hits 00:00, the used in home calculations are getting wrong. The counter increases with 10 kWh, when the solarpanels are beginning to deliver again then everything is back OK, this is around 05:30. But this gives me false reports in the future how much I use in a day. Because I sleep early (little child), I do not want to troubleshoot at this late time and I don't know how to reproduce it, but I also cannot see what I am doing wrong here. I also don't know with counter (the p1 or solar) is responsible for the increase?
This is the script that I am using. Basically I copied the script from this forum. but changed it (also to understand it for myself) to the following:
Code: Select all
-- dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.
local fetchIntervalMins = 1 -- (Integer) Minutes frequence of this script execution 1 = every minute, 10 = every 10 minutes, etc ) must be one of (1,2,3,4,5,6,10,12,15,20,30)
local ScriptVersion = '0.1.9'
return {
on = {
timer = { 'every ' .. fetchIntervalMins .. ' Minutes'}
},
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion
},
execute = function(dz, item)
-- The following need updated for your environment get the Idx or 'Name' of the Device tab.
local P1data = 1008 -- Stroom P1 sensor
local solardata = 1020 -- Solaredge sensor
local idx_usage = 1030 -- Electra used today
local idx_delivered = 1031 -- Electra delivered today
local idx_home = 1035 -- Used at home today
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
-- Read sensors
local p1Table = dz.devices(P1data)
local solarTable = dz.devices(solardata)
-- Place statistics in variables
dayDeliveredsolar = solarTable.counterToday
dayDeliveredelectra = p1Table.counterDeliveredToday
dayUsedinhouse = p1Table.counterToday
--logWrite("Totaal gebruikt: " .. dayUsedinhouse)
--logWrite("Totaal geleverd aan electra: " .. dayDeliveredelectra)
--logWrite("Totaal geleverd solar: " .. dayDeliveredsolar)
-- Update de "vandaag" devices..
local function updateCounter(idx,value)
dz.devices(idx).updateCustomSensor(value)
dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
end
updateCounter(idx_usage,dayUsedinhouse)
updateCounter(idx_delivered,dayDeliveredelectra)
-- berekenen wat vandaag in huis is gebruikt
if (dayDeliveredsolar == 0.0 ) then
dayTotal = dayUsedinhouse
else
dayTotalsolarusedinhouse = dayDeliveredsolar - dayDeliveredelectra
dayTotal = dayUsedinhouse + dayTotalsolarusedinhouse
end
-- Place in Sensor
updateCounter(idx_home,dayTotal)
end
}