Everyone thanks for the ideas. I created a dzvents script using the ideas in this thread. In no way i want to take credit for the script, because most ideas and pieces of code i found on this forum. I just combined and adjusted to my own needs, however it now works like a charm and since i could not find a fully functioning real power consumption script on this forum, i decided to give something back to the community by posting this script.
prerequisites to make it work
- Sunspec monitor installed on your system. (can be found here
https://github.com/tjko/sunspec-monitor)
- Modbus TCP enabled on your solaredge invertor on the default port (instructions can be found here
https://www.solaredge.com/sites/default ... l-note.pdf)
- a p1 smart smart meter device
- a virtual electricity device (usage, counter) to store the actual energy output of your inverter
- a virtual electricity device (usage, counter) to store the real power consumption
- a virtual temperature device to store the temperature for the inverter (not needed for real power consumption, so you can remove this part from the code if you like)
and make sure in the code below you change
- the ip adress (should be the one of your inverter).
- possible add a port number with using "-p" to the sunspec monitor (if you used another port number then the default 502 port on the inverter)
- possibly the path to sunspec monitor (depending on how you installed sunspec monitor)
- the names of the devices, so they match the devices in your domoticz system
Sorry for some dutch words in the code. But feel free to change to english and repost
Code: Select all
return {
logging = {
level = domoticz.LOG_DEBUG, -- Adjust to your needs
marker = 'ActualPowerConsumption'
},
on = {
devices = {
'Slimme Meter' -- Name of P1 Smart Meter device
}
},
execute = function(domoticz, item)
-- Get SolarEdge input using sunspec monitor
local handle = io.popen('sunspec-status -m 0 -j 192.168.2.2 || echo error')
local result = handle:read("*a")
handle:close()
-- For debugging purposes: Log result
domoticz.log ("JSON output Inverter is "..result)
-- Check if we are succesful
if(result ~= 'error\n') then
-- no error: declare needed opbjects
local SM=domoticz.devices("Slimme Meter") -- P1 Smart Meter Device
local SE=domoticz.devices("Zonnepanelen") -- Virtual Electricity device (usage, counter) in which the actual Solar Output will be stored
local SV=domoticz.devices("Stroom Verbruik") -- Virtual Electricity devie (usage, counter) in which the actual power consumption will be stored
local OT=domoticz.devices("Omvormer Temperatuur") -- Virtual Temperature device, in which the inverter temperature will be stored
local usage=SM.usage
local usagedelivered=SM.usageDelivered
domoticz.log ("Usage = "..usage ..", Delivered = "..usagedelivered..", P1 cumulative="..SM.usage1+SM.usage2-SM.return1-SM.return2)
-- convert JSON object to readable format
local json = domoticz.utils.fromJSON(result)
-- log timestamp for debugging purposes
local Time=require('Time')
domoticz.log("Timestamp inverter = "..json.timestamp..", which is "..Time(json.timestamp).secondsAgo.." second(s) ago")
-- update SolarEdge virtual sensors
domoticz.log("SE.updateElectricity("..json.dc_power..", "..json.total_production..")")
SE.updateElectricity(json.dc_power, json.total_production)
domoticz.log("OT.updateTemperature("..json.temperature..")")
OT.updateTemperature(json.temperature)
-- calculate real energy consumption
local virtuelemeterstand=json.total_production+SM.usage1+SM.usage2-SM.return1-SM.return2
local vermogen=SM.usage-SM.usageDelivered+json.dc_power
-- update real actual usage sensor
domoticz.log("SV.updateElectricity("..vermogen..","..virtuelemeterstand..")")
SV.updateElectricity(vermogen,virtuelemeterstand)
else
domoticz.log('failure with io.popen')
end
end
}
have fun! let me know if you like it.