Page 1 of 1
problem with P1 and solar meter
Posted: Tuesday 21 July 2020 20:18
by CronoS
Hi,
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
}
and this is what the report shows, where there is a spike at 00:00... I would expect that the value will go back to 0 at this time.:

Re: problem with P1 and solar meter
Posted: Tuesday 21 July 2020 21:30
by roblom
When is dayDeliveredsolar set to 0,0?
"dayTotalsolarusedinhouse = dayDeliveredsolar - dayDeliveredelectra"
Probably the dayDeliveredelectra it's set to 0 at midnight but Deliveredsolar is set to 0 at the first time the inverter is powered on again. So then "dayTotalsolarusedinhouse" is equal to "dayDeliveredsolar".
Verstuurd vanaf mijn ELE-L29 met Tapatalk
Re: problem with P1 and solar meter
Posted: Tuesday 21 July 2020 21:32
by waaren
CronoS wrote: Tuesday 21 July 2020 20:18
for some reason.. when the clock hits 00:00, the used in home calculations are getting wrong.
at 00:00 hr domoticz resets the daily totals. This process does take some time so it might well be that the script is using a yesterdays daily total from one meter and a zero value from another. Best to pauze the script for some minutes around midnight to make sure domoticz completed the process of resetting the daily totals.
The below script does prevent the interfering and has some extra debug lines to a data file . Let's see what tomorrow morning is in the historic data file.
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 between 00:02 and 23:59',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion,
},
data =
{
debugData = -- You will find this file with debugdata (build in the minutes around 00:00) in <domoticz dir>/scripts/dzVents/data directory
{
history = true,
maxItems = 20,
},
},
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)
if dz.time.matchesRule('at 23:55-00:05') then -- Building history file with debug data
debugData = {}
table.insert(debugData, 'dayTotal = ' .. tostring(dayTotal) )
table.insert(debugData, 'dayDeliveredsolar = '.. tostring(dayDeliveredsolar) )
table.insert(debugData, 'dayDeliveredelectra = '.. tostring(dayDeliveredelectra) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayUsedinhouse = ' .. tostring(dayUsedinhouse ) )
dz.data.debugData.add(debugData)
end
end
}
Re: problem with P1 and solar meter
Posted: Tuesday 21 July 2020 21:38
by CronoS
Thanks.. I also saw it now

Awesome, thanks! .
Hopefully this the correct matchesRule syntax, , I have added this to my script:
Code: Select all
{
timer = { 'every ' .. fetchIntervalMins .. ' Minutes','00:00 - 15 minutes after sunrise'}
},
and...
Code: Select all
local ptime = dz.time
if (ptime.matchesRule('00:00 - 15 minutes after sunrise')) then
dayDeliveredsolar = 0.0
end
and changed this, just to be sure that it follows it correctly...
Code: Select all
if (dayDeliveredsolar == 0.0 ) then
dayTotal = dayUsedinhouse
elseif (dayDeliveredsolar ~= 0.0 ) then
dayTotalsolarusedinhouse = dayDeliveredsolar - dayDeliveredelectra
dayTotal = dayUsedinhouse + dayTotalsolarusedinhouse
end
Re: problem with P1 and solar meter
Posted: Tuesday 21 July 2020 22:15
by waaren
CronoS wrote: Tuesday 21 July 2020 21:38
Thanks.. I also saw it now

Awesome, thanks! .
Hopefully this the correct matchesRule syntax, , I have added this to my script:
Please use for now the changed script I posted. your timer rule is incorrect and I don't see the debug part that I included.
Re: problem with P1 and solar meter
Posted: Wednesday 22 July 2020 6:57
by CronoS
I have added you're script. but, got an error on the table part", any idea?:
"bad argument #1 to 'insert' (table expected, got nil)
It is on this line of the code:
One thing only, when I look at the report: the value's stay high until the Solaredge is switched on. So maybe on the Solaredge Web portal values still be there until the solaredge is coming out of hibernate at sunrise... I would suspect otherwise that my Domoticz report would have shown only a short spke for a few minutes.. but the spike is more then 5 hours after midnight.
Re: problem with P1 and solar meter
Posted: Wednesday 22 July 2020 8:52
by waaren
CronoS wrote: Wednesday 22 July 2020 6:57
I have added you're script. but, got an error on the table part", any idea?:
"bad argument #1 to 'insert' (table expected, got nil)
It is on this line of the code:
I removed the two test lines I left in accidentally in the posted script. Can you try again with this?
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 between 00:02 and 23:59',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion,
},
data =
{
debugData = -- You will find this file with debugdata (build in the minutes around 00:00) in <domoticz dir>/scripts/dzVents/data directory
{
history = true,
maxItems = 20,
},
},
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)
if dz.time.matchesRule('at 23:55-00:05') then -- Building history file with debug data
debugData = {}
table.insert(debugData, 'dayTotal = ' .. tostring(dayTotal) )
table.insert(debugData, 'dayDeliveredsolar = '.. tostring(dayDeliveredsolar) )
table.insert(debugData, 'dayDeliveredelectra = '.. tostring(dayDeliveredelectra) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayUsedinhouse = ' .. tostring(dayUsedinhouse ) )
dz.data.debugData.add(debugData)
end
end
}
Re: problem with P1 and solar meter
Posted: Wednesday 22 July 2020 20:03
by CronoS
Thanks Waaren; the script starts OK. Let's find out what will happen this night

I will keep you updated..!
Re: problem with P1 and solar meter
Posted: Thursday 23 July 2020 12:01
by CronoS
Unfortunately, I got the same issue as shown in the report earlier in this topic.
I think the problem is that my SolarEdge is going in sleep mode and does not update the value anymore. When the clock hits 00:00 the same value will be readen from the Solaredge portal and therefor I get the spike. When at sunrise , the solaredge is going out of the sleep mode and updates the portal and basically resets it.
So between 00:00 and some minutes after sunrise the Solaredge value must be zero I think; What is the best way to achieve this?
Re: problem with P1 and solar meter
Posted: Thursday 23 July 2020 12:47
by waaren
CronoS wrote: Thursday 23 July 2020 12:01
Unfortunately, I got the same issue as shown in the report earlier in this topic.
I think the problem is that my SolarEdge is going in sleep mode and does not update the value anymore. When the clock hits 00:00 the same value will be readen from the Solaredge portal and therefor I get the spike. When at sunrise , the solaredge is going out of the sleep mode and updates the portal and basically resets it.
So between 00:00 and some minutes after sunrise the Solaredge value must be zero I think; What is the best way to achieve this?
Can you share the data file that is produced by the script. You will find it in <domoticz dir>/scripts/dzVents/data/*scriptname*
Re: problem with P1 and solar meter
Posted: Thursday 23 July 2020 13:03
by CronoS
Hi,
This is the outcome of that file:
Code: Select all
-- Persistent Data
local multiRefObjects = {
} -- multiRefObjects
local obj1 = {
["debugData"] = {
[1] = {
["data"] = {
[1] = "dayTotal = 26.241";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 0.0";
[4] = "dayTotalsolarusedinhouse = 26.22";
[5] = "dayTotalsolarusedinhouse = 26.22";
[6] = "dayUsedinhouse = 0.021";
};
["time"] = "2020-7-22 22:4:0.275";
};
[2] = {
["data"] = {
[1] = "dayTotal = 26.236";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 0.0";
[4] = "dayTotalsolarusedinhouse = 26.22";
[5] = "dayTotalsolarusedinhouse = 26.22";
[6] = "dayUsedinhouse = 0.016";
};
["time"] = "2020-7-22 22:3:0.526";
};
[3] = {
["data"] = {
[1] = "dayTotal = 26.23";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 0.0";
[4] = "dayTotalsolarusedinhouse = 26.22";
[5] = "dayTotalsolarusedinhouse = 26.22";
[6] = "dayUsedinhouse = 0.01";
};
["time"] = "2020-7-22 22:2:0.195";
};
[4] = {
["data"] = {
[1] = "dayTotal = 13.405";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 17.754";
[4] = "dayTotalsolarusedinhouse = 8.466";
[5] = "dayTotalsolarusedinhouse = 8.466";
[6] = "dayUsedinhouse = 4.939";
};
["time"] = "2020-7-22 21:59:0.76";
};
[5] = {
["data"] = {
[1] = "dayTotal = 13.401";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 17.754";
[4] = "dayTotalsolarusedinhouse = 8.466";
[5] = "dayTotalsolarusedinhouse = 8.466";
[6] = "dayUsedinhouse = 4.935";
};
["time"] = "2020-7-22 21:58:0.336";
};
[6] = {
["data"] = {
[1] = "dayTotal = 13.398";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 17.754";
[4] = "dayTotalsolarusedinhouse = 8.466";
[5] = "dayTotalsolarusedinhouse = 8.466";
[6] = "dayUsedinhouse = 4.932";
};
["time"] = "2020-7-22 21:57:0.146";
};
[7] = {
["data"] = {
[1] = "dayTotal = 13.394";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 17.754";
[4] = "dayTotalsolarusedinhouse = 8.466";
[5] = "dayTotalsolarusedinhouse = 8.466";
[6] = "dayUsedinhouse = 4.928";
};
["time"] = "2020-7-22 21:56:0.315";
};
[8] = {
["data"] = {
[1] = "dayTotal = 13.39";
[2] = "dayDeliveredsolar = 26.22";
[3] = "dayDeliveredelectra = 17.754";
[4] = "dayTotalsolarusedinhouse = 8.466";
[5] = "dayTotalsolarusedinhouse = 8.466";
[6] = "dayUsedinhouse = 4.924";
};
["time"] = "2020-7-22 21:55:0.145";
};
};
}
return obj1
Re: problem with P1 and solar meter
Posted: Thursday 23 July 2020 14:45
by waaren
CronoS wrote: Thursday 23 July 2020 13:03
This is the outcome of that file:
Thx. This shows that the solarData dayTotal is not reset to 0 at midnight.
Can you try this?
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 between 00:02 and 23:59',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion,
},
data =
{
debugData = -- You will find this file with debugdata (build in the minutes around 00:00) in <domoticz dir>/scripts/dzVents/data directory
{
history = true,
maxItems = 20,
},
dayDeliveredsolar =
{
initial = 0,
},
},
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
local dayDeliveredsolar = solarTable.counterToday
local dayDeliveredelectra = p1Table.counterDeliveredToday
local dayUsedinhouse = p1Table.counterToday
-- store current dayDeliveredsolar
if dz.time.matchesRule('at 23:30-23:59') then
dz.data.dayDeliveredsolar = dayDeliveredsolar
end
-- check dayDeliveredsolar and set to 0 when required
if dz.time.matchesRule('at 00:00-09:00') then
if dz.data.dayDeliveredsolar <= dayDeliveredsolar then
dayDeliveredsolar = 0
end
end
--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)
if dz.time.matchesRule('at 23:55-00:05') then -- Building history file with debug data
debugData = {}
table.insert(debugData, 'dayTotal = ' .. tostring(dayTotal) )
table.insert(debugData, 'dayDeliveredsolar = '.. tostring(dayDeliveredsolar) )
table.insert(debugData, 'dayDeliveredelectra = '.. tostring(dayDeliveredelectra) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayUsedinhouse = ' .. tostring(dayUsedinhouse ) )
dz.data.debugData.add(debugData)
end
end
}
Re: problem with P1 and solar meter
Posted: Thursday 23 July 2020 15:47
by CronoS
Placed it... Let see what happens tonight!

Re: problem with P1 and solar meter
Posted: Friday 24 July 2020 9:05
by CronoS
Thanks Waaren; it seems that it worked last night !
One question though.. In the script the "table.insert" code; is that still necessary in order to let it work? Otherwise maybe I can disable those lines...
Re: problem with P1 and solar meter
Posted: Friday 24 July 2020 10:27
by waaren
CronoS wrote: Friday 24 July 2020 9:05
One question though.. In the script the "table.insert" code; is that still necessary in order to let it work? Otherwise maybe I can disable those lines...
The lines in the two blocks below can be deleted from the script when it works OK. They were just there to help debugging.
Code: Select all
debugData = -- You will find this file with debugdata (build in the minutes around 00:00) in <domoticz dir>/scripts/dzVents/data directory
{
history = true,
maxItems = 20,
},
Code: Select all
if dz.time.matchesRule('at 23:55-00:05') then -- Building history file with debug data
debugData = {}
table.insert(debugData, 'dayTotal = ' .. tostring(dayTotal) )
table.insert(debugData, 'dayDeliveredsolar = '.. tostring(dayDeliveredsolar) )
table.insert(debugData, 'dayDeliveredelectra = '.. tostring(dayDeliveredelectra) )
table.insert(debugData, 'dayTotalsolarusedinhouse = '.. tostring(dayTotalsolarusedinhouse ) )
table.insert(debugData, 'dayUsedinhouse = ' .. tostring(dayUsedinhouse ) )
dz.data.debugData.add(debugData)
end
Re: problem with P1 and solar meter [Solved]
Posted: Friday 24 July 2020 11:42
by CronoS
Thanks!!!