Thanks waaren. It is not the nicest script, it does more then only that. So hopefully you can read it OK, if not I don't blame you
But here it is:
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'
local fetchIntervalMins = 1
return
{
on =
{
devices = {'SolarEdge Act. Vermogen (AC)','Stroom P1'},
timer = { 'every minute between 16 minutes after sunset and 16 minutes before sunrise' }
},
logging =
{
level = domoticz.LOG_INFO, -- Uncomment this line to override the dzVents global logging setting LOG_DEBUG for debug loggin
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 = 1055 -- Solaredge sensor
local idx_usage = 1030 -- Electra used today
local idx_delivered = 1031 -- Electra delivered today
local idx_home_watt = 1104 -- Used at home watt sensor
local idx_home_kWh = 1035 -- Used at home seperate kWh sensor
local idx_solar = 1058 -- used solar in house
local idx_solar_watt = 1155 -- used solar in house
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
-- Read Totals kWh
local dayDeliveredsolar = solarTable.counterToday
local dayDeliveredelectra = p1Table.counterDeliveredToday
local dayUsedinhouse = p1Table.counterToday
logWrite("Geleverd zonnepanelen: " .. dayDeliveredsolar)
-- Read Total Watts
local WattDeliveredsolarActual = solarTable.actualWatt
local WattUsageActual = p1Table.usage
local WattDeliveredActual = p1Table.usageDelivered
logWrite("Watt solar Actual (WattDeliveredsolarActual): " .. WattDeliveredsolarActual)
logWrite("Watt p1 Actual usage (WattUsageActual): " .. WattUsageActual)
logWrite("Watt p1 Actual delivered (WattDeliveredActual): " .. WattDeliveredActual)
-- 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
WattDeliveredsolarActualReset = 0
end
end
--logWrite("Totaal gebruikt: " .. dayUsedinhouse)
--logWrite("Totaal geleverd aan electra: " .. dayDeliveredelectra)
--logWrite("Totaal geleverd solar: " .. dayDeliveredsolar)
-- Update de "vandaag" devices..
local function updateCountergeneral(idx,value)
dz.devices(idx).updateCustomSensor(value)
dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
end
local function updateCounterkWh(idx,power_value)
dz.devices(idx).updateElectricity(power_value,0)
dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
end
updateCountergeneral(idx_usage,dayUsedinhouse)
updateCountergeneral(idx_delivered,dayDeliveredelectra)
-- berekenen wat vandaag in huis is gebruikt
if (dayDeliveredsolar == 0.0 ) then
dayTotal = dayUsedinhouse
else
-- Calculation of the total value
dayTotalsolarusedinhouse = dayDeliveredsolar - dayDeliveredelectra
dayTotal = dayUsedinhouse + dayTotalsolarusedinhouse
end
-- berekenen wat vandaag in huis is gebruikt in Watt
if (WattDeliveredsolarActualReset == 0.0 ) then
TotalWatt = WattUsageActual
else
-- Calculation of Watt is being used now
-- Compare if WattDeliveredsolarActual is not lower then WattDeliveredActual, wrong value; timing problem
if WattDeliveredsolarActual < WattDeliveredActual then
TotalWatt = WattUsageActual
logWrite("TotalWatt fout: " .. TotalWatt)
end
--if compare if WattDeliveredsolarActual is larger thenWattDeliveredActual, OK value
if WattDeliveredsolarActual >= WattDeliveredActual then
TotalWattInhouse = WattDeliveredsolarActual - WattDeliveredActual
logWrite("TotalWattInhouse Solar goed: " .. TotalWattInhouse)
TotalWatt = TotalWattInhouse + WattUsageActual
logWrite("TotalWatt goed: " .. TotalWatt)
end
end
-- Place in Sensor
updateCounterkWh(idx_home_watt,TotalWatt)
updateCounterkWh(idx_solar_watt,TotalWattInhouse)
updateCountergeneral(idx_home_kWh,dayTotal)
updateCountergeneral(idx_solar,dayTotalsolarusedinhouse)
--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
}
Device 1104: is an Electric device which shows the total Watt production, the device itself compute it to kWh
Device 1035: This device takes the absolute powerconsumption and place it as a general custom device
Device 1155 is also an Electric device which shows the totall Watt I used in house, just coming from Solar. Also the device itself compute it to kWh
Device 1058: This device takes the absolute solar usage in house, so looking at the total solar consumption in kWh and put it in a general custom device