Page 1 of 1
Timing challenge
Posted: Saturday 11 July 2020 12:21
by roblom
I have the current situation:
* RPi on the attic
- Connected to SolarRiver PV inverter from SamilPower with a serial to USB cable.
- Perl script reads out every minute the inverter data and adds it to Domoticz
* RPi in fuse box on the ground floor.
- connected to my smart meter on the P1 port.
- DzEvents script on this RPi collects data from PV and P1 and calculates the real consumption using PV and P1 as trigger.
- DzEvents script uploads all data to pvoutput.
The problem that I have is that I sometimes have negative consumption values which is caused by a timing problem. The consumption script is triggered on a change of the PV script (which runs every minute) but it is also triggered by a change of the P1. But as these are not updating synchronous there is a chance the generated power is lower than the exported power.
PowerConsumption = -185.0 W
PowerGeneration = 635 W
PowerImport = 0 W
PowerExport = 820 W
(635 + 0 - 820 = -185)
If I use for the consumption calculation script only use the PV as a trigger it works probably better but then I'm missing a trigger of the sun goes down.
If I only use the P1 as a trigger then the problem probably gets bigger as it's then missing the update of the PV update.
Somebody knows a good solution?
Verstuurd vanaf mijn ELE-L29 met Tapatalk
Re: Timing challenge
Posted: Saturday 11 July 2020 12:32
by waaren
roblom wrote: Saturday 11 July 2020 12:21
The problem that I have is that I sometimes have negative consumption values which is caused by a timing problem. The consumption script is triggered on a change of the PV script (which runs every minute) but it is also triggered by a change of the P1. But as these are not updating synchronous there is a chance the generated power is lower than the exported power.
Can you share the script(s) ? My abstraction level is not sufficient to oversee all scenarios based on your description.
Re: Timing challenge
Posted: Saturday 11 July 2020 15:57
by roblom
Here are the scripts.
The perl script exists out of multiple files and was coming from a website that does no longer exists (I installed it on 2014). But
this website describes it also and I think it's the same script (or at least it has the same source). The protocol has been at least partially document in
this PDF. This script is for me very complex (partly because it also should work on Windows which is not needed for me so a lot of code is useless) and this als causes that I'm not able to update domoticz because I can't get the script to work on buster. Is it possible to readout a serial device by using DzEvents?
The other consumption.lua script is a DzEvents script that was coming from this forum but I modified it a bit to suit my needs.
Re: Timing challenge
Posted: Saturday 11 July 2020 20:45
by waaren
roblom wrote: Saturday 11 July 2020 15:57
and this als causes that I'm not able to update domoticz because I can't get the script to work on buster. Is it possible to readout a serial device by using dzVents?
If you have a bash script that could read the meter for example with cu with a command like
Code: Select all
sudo cu -l /dev/ttyUSB -s 115200 --parity=none -E q
It would be relatively easy to transfer the values to a dzVents script for further processing using a curl to the domoticz API.
The other consumption.lua script is a DzEvents script that was coming from this forum but I modified it a bit to suit my needs.
Think I understand now.
My approach would be to store the PowerImport and PowerExport from the Smartmeter and PowerGeneration from the Solar Panels in dzVents persistent historical data and take the average of the last n measures to compute a (smoothend) internal PowerConsumption value.
Please feel free to let me know if I can help you with that.
Re: Timing challenge
Posted: Tuesday 14 July 2020 23:26
by roblom
waaren wrote: Saturday 11 July 2020 20:45
If you have a bash script that could read the meter for example with cu with a command like
Code: Select all
sudo cu -l /dev/ttyUSB -s 115200 --parity=none -E q
It would be relatively easy to transfer the values to a dzVents script for further processing using a curl to the domoticz API.
It's currently mostly based on a perl script and its above my capabilities to transfer that into a bash script I think.
My approach would be to store the PowerImport and PowerExport from the Smartmeter and PowerGeneration from the Solar Panels in dzVents
I understand your approach, but does the problem then persists only then with an average value?
Re: Timing challenge
Posted: Tuesday 14 July 2020 23:58
by waaren
roblom wrote: Tuesday 14 July 2020 23:26
I understand your approach, but does the problem then persists only then with an average value?
I don't think so because the calculation is done on the summed values. It will never be 100% accurate but much closer to reality then with single values.
Re: Timing challenge
Posted: Thursday 16 July 2020 0:28
by roblom
Ok, I need help. When I use the code below I get an error
2020-07-16 00:26:24.344 Error: dzVents: Error: (3.0.11) Consumption: Item data is not a number type. Type is nil
2020-07-16 00:26:24.345 Error: dzVents: Error: (3.0.11) Consumption: An error occurred when calling event handler consumption
2020-07-16 00:26:24.345 Error: dzVents: Error: (3.0.11) Consumption: /home/pi/domoticz/dzVents/runtime/HistoricalStorage.lua:289: attempt to perform arithmetic on a nil value (local 'sum')
So probably the used data values are not a number but I don't know how to change that.
Code: Select all
-- This script collects the values below from Domoticz
-- * The Power and energy values (import and export) from a smartmeter
-- * The Power and energy values from a Solar power inverter
-- It then calculates the consumed power and energy from the values above with the formula's
-- * EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
-- * PowerConsumption = PowerGeneration + PowerImport - PowerExport
-- It then updates a virtual device which displays the consumed power and energy in Domoticz
-- The base of this scrip comes from
-- https://www.domoticz.com/forum/viewtopic.php?f=61&t=4714&p=251778#p251778
return {
active = true,
on = {
devices = {
-- Devices on which this calculation script should trigger. These should be the same as the IDX of Smartmeter and/or IDX of Solar Panels
175, -- IDX of Smart meter (youless or P1)
96, -- IDX of Solar Panels
}
},
logging = {
-- level = domoticz.LOG_INFO,
level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_ERROR,
marker = "Consumption"
},
data = {
PowerImportHistory = { history = true, maxItems = 3 },
PowerExportHistory = { history = true, maxItems = 3 },
PowerGenerationHistory = { history = true, maxItems = 3 }
},
execute = function(dz, item)
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of the needed devices
----------------------------------------------------------------------------------------------------------
local Smartmeter = dz.devices(175) -- IDX of Smart meter (youless or P1)
local Generation = dz.devices(96) -- IDX of Solar Panels
local Consumption = dz.devices(93) -- IDX of Own Usage / calculated value / dummy Elekta kWh + counter
----------------------------------------------------------------------------------------------------------
-- Smartmeter
----------------------------------------------------------------------------------------------------------
local EnergyImportLow = Smartmeter.rawData[1]
local EnergyImportHigh = Smartmeter.rawData[2]
local EnergyExportLow = Smartmeter.rawData[3]
local EnergyExportHigh = Smartmeter.rawData[4]
-- Because power fluctuates much, use average
local PowerImportHistory = dz.data.PowerImportHistory
local PowerExportHistory = dz.data.PowerExportHistory
-- add new data
dz.data.PowerImportHistory.add(Smartmeter.rawData[5])
dz.data.PowerExportHistory.add(Smartmeter.rawData[6])
-- calcuate average
local PowerImport = dz.data.PowerImportHistory.avg()
local PowerExport = dz.data.PowerExportHistory.avg()
-- Values without historical data
--local PowerImport = Smartmeter.rawData[5]
--local PowerExport = Smartmeter.rawData[6]
----------------------------------------------------------------------------------------------------------
-- Generation
----------------------------------------------------------------------------------------------------------
local EnergyGeneration = Generation.rawData[2]
-- Because power fluctuates much, use average
local PowerGenerationHistory = dz.data.PowerGenerationHistory
-- add new data
dz.data.PowerGenerationHistory.add(Generation.rawData[1])
-- calcuate average
local PowerGeneration = dz.data.PowerGenerationHistory.avg()
-- Values without historical data
--local PowerGeneration = Generation.rawData[1]
----------------------------------------------------------------------------------------------------------
-- Calculate
----------------------------------------------------------------------------------------------------------
local EnergyImport = EnergyImportLow + EnergyImportHigh
local EnergyExport = EnergyExportLow + EnergyExportHigh
local EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
local PowerConsumption = PowerGeneration + PowerImport - PowerExport
--[[
dz.log('EnergyImportLow ' .. EnergyImportLow .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyImportHigh ' .. EnergyImportHigh .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyExportLow ' .. EnergyExportLow .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyExportHigh ' .. EnergyExportHigh .. ' Wh ', dz.LOG_INFO)
dz.log('PowerImport ' .. PowerImport .. ' W ', dz.LOG_INFO)
dz.log('PowerExport ' .. PowerExport .. ' W ', dz.LOG_INFO)
dz.log('EnergyGeneration ' .. EnergyGeneration .. ' Wh ', dz.LOG_INFO)
dz.log('PowerGeneration ' .. PowerGeneration .. ' W ', dz.LOG_INFO)
dz.log('EnergyConsumption ' .. EnergyConsumption/1000 .. ' kWh ', dz.LOG_INFO)
dz.log('PowerConsumption: ' .. PowerConsumption .. ' W ', dz.LOG_INFO)
]]--
if PowerConsumption < 0 then
dz.log('PowerConsumption (NEGATIVE): ' .. PowerConsumption .. ' W = ', dz.LOG_ERROR)
dz.log('PowerGeneration ' .. PowerGeneration .. ' W + ', dz.LOG_ERROR)
dz.log('PowerImport ' .. PowerImport .. ' W - ', dz.LOG_ERROR)
dz.log('PowerExport ' .. PowerExport .. ' W ', dz.LOG_ERROR)
else
dz.log('PowerConsumption (POSITIVE): ' .. PowerConsumption .. ' W = ', dz.LOG_INFO)
end
----------------------------------------------------------------------------------------------------------
-- Update
----------------------------------------------------------------------------------------------------------
Consumption.updateElectricity(PowerConsumption, EnergyConsumption)
end
}
Re: Timing challenge
Posted: Thursday 16 July 2020 9:33
by waaren
roblom wrote: Thursday 16 July 2020 0:28
Ok, I need help. When I use the code below I get an error
So probably the used data values are not a number but I don't know how to change that.
rawData[n] is always a string; if you need it to be a number use something like tonumber(Generation.rawdata[1]) but better to use the right attribute like usage or powerYield. (check the wiki)
If you use a native dzVents attribute it will have the right type.
can you check below script ?
Code: Select all
--[[
This script collects the values below from Domoticz
* The Power and energy values (import and export) from a smartmeter
* The Power and energy values from a Solar power inverter
It then calculates the consumed power and energy from the values above with the formula's
* EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
* PowerConsumption = PowerGeneration + PowerImport - PowerExport
It then updates a virtual device which displays the consumed power and energy in Domoticz
The base of this scrip comes from
https://www.domoticz.com/forum/viewtopic.php?f=61&t=4714&p=251778#p251778
]]--
local smartMeterIDX = 175
local solarPanelsIDX = 96
local consumptionIDX = 93
return {
active = true,
on =
{
devices =
{
-- Devices on which this calculation script should trigger. These should be the same as the IDX of Smartmeter and/or IDX of Solar Panels
smartMeterIDX, -- Smart meter (youless or P1)
solarPanelsIDX, -- Solar Panels
},
},
logging =
{
-- level = domoticz.LOG_INFO,
level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_ERROR,
marker = 'Consumption',
},
data =
{
PowerImportHistory = { history = true, maxMinutes = 4 },
PowerExportHistory = { history = true, maxMinutes = 4 },
PowerGenerationHistory = { history = true, maxMinutes = 4 },
},
execute = function(dz, item)
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of the needed devices
----------------------------------------------------------------------------------------------------------
local Smartmeter = dz.devices(smartMeterIDX) -- Smart meter (youless or P1)
local Generation = dz.devices(solarPanelsIDX) -- Solar Panels
local Consumption = dz.devices(consumptionIDX) -- IDX of Own Usage / calculated value / dummy Elekta kWh + counter
----------------------------------------------------------------------------------------------------------
-- Smartmeter
----------------------------------------------------------------------------------------------------------
local EnergyImportLow = Smartmeter.usage1
local EnergyImportHigh = Smartmeter.usage2
local EnergyExportLow = Smartmeter.return1
local EnergyExportHigh = Smartmeter.return2
-- add new data
if item == Smartmeter then
dz.data.PowerImportHistory.add(Smartmeter.usage)
dz.data.PowerExportHistory.add(Smartmeter.usageDelivered)
end
----------------------------------------------------------------------------------------------------------
-- Generation
----------------------------------------------------------------------------------------------------------
-- add new data
if item == Generation then
-- powerYield attribute is available for device type Youless
dz.data.PowerGenerationHistory.add(Generation.powerYield) -- What is the type subtype of this meter ??
end
local EnergyGeneration = Generation.rawData[2] -- You should only use rawData if no native dzVents attribute exists
----------------------------------------------------------------------------------------------------------
-- Check historical storage entries
----------------------------------------------------------------------------------------------------------
if dz.data.PowerImportHistory.size < 3 or dz.data.PowerGenerationHistory.size < 3 then
dz.log('Not enough data points yet to produce something useful', dz.LOG_DEBUG)
dz.log('PowerImportHistory entries = ' .. dz.data.PowerImportHistory.size, dz.LOG_DEBUG)
dz.log('PowerGeneration entries = ' .. dz.data.PowerGenerationHistory.size, dz.LOG_DEBUG)
return
end
----------------------------------------------------------------------------------------------------------
-- Calculate
----------------------------------------------------------------------------------------------------------
-- average PowerGeneration
local PowerGeneration = dz.data.PowerGenerationHistory.avgSince('00:03:00')
-- smartMeter averages
local PowerImport = dz.data.PowerImportHistory.avgSince('00:03:00')
local PowerExport = dz.data.PowerExportHistory.avgSince('00:03:00')
local EnergyImport = EnergyImportLow + EnergyImportHigh
local EnergyExport = EnergyExportLow + EnergyExportHigh
local EnergyConsumption = dz.utils.round(EnergyGeneration + EnergyImport - EnergyExport, 2)
local PowerConsumption = dz.utils.round(PowerGeneration + PowerImport - PowerExport, 2)
--[[
dz.log('EnergyImportLow ' .. EnergyImportLow .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyImportHigh ' .. EnergyImportHigh .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyExportLow ' .. EnergyExportLow .. ' Wh ', dz.LOG_INFO)
dz.log('EnergyExportHigh ' .. EnergyExportHigh .. ' Wh ', dz.LOG_INFO)
dz.log('PowerImport ' .. PowerImport .. ' W ', dz.LOG_INFO)
dz.log('PowerExport ' .. PowerExport .. ' W ', dz.LOG_INFO)
dz.log('EnergyGeneration ' .. EnergyGeneration .. ' Wh ', dz.LOG_INFO)
dz.log('PowerGeneration ' .. PowerGeneration .. ' W ', dz.LOG_INFO)
dz.log('EnergyConsumption ' .. EnergyConsumption/1000 .. ' kWh ', dz.LOG_INFO)
dz.log('PowerConsumption: ' .. PowerConsumption .. ' W ', dz.LOG_INFO)
]]--
if PowerConsumption < 0 then
dz.log('PowerConsumption (NEGATIVE): ' .. PowerConsumption .. ' W = ', dz.LOG_ERROR)
dz.log('PowerGeneration ' .. PowerGeneration .. ' W + ', dz.LOG_ERROR)
dz.log('PowerImport ' .. PowerImport .. ' W - ', dz.LOG_ERROR)
dz.log('PowerExport ' .. PowerExport .. ' W ', dz.LOG_ERROR)
else
dz.log('PowerConsumption (POSITIVE): ' .. PowerConsumption .. ' W = ', dz.LOG_INFO)
end
----------------------------------------------------------------------------------------------------------
-- Update device
----------------------------------------------------------------------------------------------------------
Consumption.updateElectricity(PowerConsumption, EnergyConsumption)
end
}
Re: Timing challenge
Posted: Friday 17 July 2020 15:18
by roblom
Thanks for your help.
It is not a Youless device I'm using. But apart from that, are you sure about the therm "powerYield"? I'm a Dutch mechanical engineer so the term "yield" get a bit lost in translation to my Dutch and also it's not mechanical but what's the unit of this powerYield?
I am using a virtual device called "general" as a type and "kWh" as subtype. The "actualWatt" from the dzVents "Electric usage" does work but cant find the attribute for the Energy (kWh). Also the "WhActual" gives the same value as the "actualWatt".
The /json.htm?type=devices&rid=93 gives:
Code: Select all
{
"ActTime" : 1594991498,
"AstrTwilightEnd" : "00:00",
"AstrTwilightStart" : "00:00",
"CivTwilightEnd" : "22:42",
"CivTwilightStart" : "04:52",
"DayLength" : "16:17",
"NautTwilightEnd" : "23:51",
"NautTwilightStart" : "03:43",
"ServerTime" : "2020-07-17 15:11:38",
"SunAtSouth" : "13:47",
"Sunrise" : "05:38",
"Sunset" : "21:55",
"app_version" : "2020.2 (build 12227)",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CounterToday" : "4.825 kWh",
"CustomImage" : 0,
"Data" : "9443.960 kWh",
"Description" : "",
"EnergyMeterMode" : "",
"Favorite" : 1,
"HardwareID" : 18,
"HardwareName" : "Smartmeter",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveTimeout" : false,
"ID" : "000140D8",
"LastUpdate" : "2020-07-17 15:11:33",
"Name" : "Consumptie",
"Notifications" : "false",
"PlanID" : "4",
"PlanIDs" :
[
4
],
"Protected" : true,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "kWh",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "current",
"Unit" : 1,
"Usage" : "376.596 Watt",
"Used" : 1,
"XOffset" : "262",
"YOffset" : "447",
"idx" : "93"
}
],
"status" : "OK",
"title" : "Devices"
}
Re: Timing challenge
Posted: Friday 17 July 2020 16:04
by roblom
I see you calculate the average over 3 minutes. But isn't that way to long? For me the power insight is interesting for the big spikes. On the height of these spikes I can recognize several devices. For example a short 1500W spike is probably our coffee machine, while 1500W for a longer period is probably our vacuum cleaner. Calculating the average over a longer time flatten out these curves too much I think.
Re: Timing challenge
Posted: Friday 17 July 2020 16:15
by waaren
roblom wrote: Friday 17 July 2020 16:04
I see you calculate the average over 3 minutes. But isn't that way to long? For me the power insight is interesting for the big spikes. On the height of these spikes I can recognize several devices. For example a short 1500W spike is probably our coffee machine, while 1500W for a longer period is probably our vacuum cleaner. Calculating the average over a longer time flatten out these curves too much I think.
Look for the used attribute names in the dzVents wiki.
power yield zelfstandig naamwoord
stroomopbrengst zelfst. nw.
If you make the average shorter you might hit the unwanted negative values again. What I understand form the scripts you posted the solarPanel values are only updated once a minute. My smartmeter is updated every 10 seconds.
I don't know another way of preventing this for your situation.
Re: Timing challenge
Posted: Saturday 18 July 2020 18:02
by roblom
Excuse me, I was looking in the wiki but was looking at the "Electric usage" but I had to look at the "kWh, Electricity (instant and counter)". It solved the issue. It works well now (thanks to Waaren) and am testing what the best time period is to calculate the average without getting negative consumption.
For those who are interested, the current script below.
Code: Select all
--[[
This script collects the values below from Domoticz
* The Power and energy values (import and export) from a smartmeter
* The Power and energy values from a Solar power inverter
It then calculates the (average) consumed power and energy from the values above with the formula's
* EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
* PowerConsumption = PowerGeneration + PowerImport - PowerExport
The average power is calculated because it fluctuates much and can cause negative consumption due to timing issues.
It then updates a virtual device which displays the consumed power and energy in Domoticz
The base of this scrip comes from
https://www.domoticz.com/forum/viewtopic.php?f=61&t=4714&p=251778#p251778
]]--
local smartMeterIDX = 175 -- IDX of Smart meter device
local solarPanelsIDX = 96 -- IDX of Solar Panels device
local consumptionIDX = 93 -- IDX of Own Usage / calculated value / dummy Elekta kWh + counter
return {
active = true,
on =
{
devices =
{
-- Devices on which this calculation script should trigger.
smartMeterIDX,
solarPanelsIDX,
}
},
logging =
{
--level = domoticz.LOG_DEBUG,
level = domoticz.LOG_ERROR,
marker = 'Consumption',
},
data =
{
PowerImportHistory = { history = true, maxMinutes = 4 },
PowerExportHistory = { history = true, maxMinutes = 4 },
PowerGenerationHistory = { history = true, maxMinutes = 4 },
},
execute = function(dz, item)
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of the needed devices
----------------------------------------------------------------------------------------------------------
local Smartmeter = dz.devices(smartMeterIDX)
local Generation = dz.devices(solarPanelsIDX)
local Consumption = dz.devices(consumptionIDX)
----------------------------------------------------------------------------------------------------------
-- Smartmeter
----------------------------------------------------------------------------------------------------------
-- Energy import and export
local EnergyImportLow = Smartmeter.usage1
dz.log('EnergyImportLow = ' .. EnergyImportLow/1000 .. ' kWh ', dz.LOG_DEBUG)
local EnergyImportHigh = Smartmeter.usage2
dz.log('EnergyImportHigh = ' .. EnergyImportHigh/1000 .. ' kWh ', dz.LOG_DEBUG)
local EnergyExportLow = Smartmeter.return1
dz.log('EnergyExportLow = ' .. EnergyExportLow/1000 .. ' kWh ', dz.LOG_DEBUG)
local EnergyExportHigh = Smartmeter.return2
dz.log('EnergyExportHigh = ' .. EnergyExportHigh/1000 .. ' kWh ', dz.LOG_DEBUG)
local EnergyImport = EnergyImportLow + EnergyImportHigh
local EnergyExport = EnergyExportLow + EnergyExportHigh
-- Power import and export
-- Add new data for calculating average
if item == Smartmeter then
dz.data.PowerImportHistory.add(Smartmeter.usage)
dz.data.PowerExportHistory.add(Smartmeter.usageDelivered)
end
----------------------------------------------------------------------------------------------------------
-- Generation
----------------------------------------------------------------------------------------------------------
-- Energy generated
local EnergyGeneration = Generation.WhTotal
dz.log('EnergyGeneration = ' .. EnergyGeneration .. ' Wh ', dz.LOG_DEBUG)
-- Power generated
-- Add new data for calculating average
if item == Generation then
dz.data.PowerGenerationHistory.add(Generation.actualWatt)
end
----------------------------------------------------------------------------------------------------------
-- Check historical storage entries
----------------------------------------------------------------------------------------------------------
if dz.data.PowerImportHistory.size < 3 or dz.data.PowerGenerationHistory.size < 3 then
dz.log('Not enough data points yet to produce something useful', dz.LOG_DEBUG)
dz.log('PowerImportHistory entries = ' .. dz.data.PowerImportHistory.size, dz.LOG_DEBUG)
dz.log('PowerGeneration entries = ' .. dz.data.PowerGenerationHistory.size, dz.LOG_DEBUG)
return
end
----------------------------------------------------------------------------------------------------------
-- Calculate
----------------------------------------------------------------------------------------------------------
-- Average power generated
local PowerGeneration = dz.utils.round(dz.data.PowerGenerationHistory.avgSince('00:00:30'), 2)
dz.log('PowerGeneration = ' .. PowerGeneration .. ' W ', dz.LOG_DEBUG)
-- Average power imported and exported
local PowerImport = dz.utils.round(dz.data.PowerImportHistory.avgSince('00:00:30'), 2)
dz.log('PowerImport = ' .. PowerImport .. ' W ', dz.LOG_DEBUG)
local PowerExport = dz.utils.round(dz.data.PowerExportHistory.avgSince('00:00:30'), 2)
dz.log('PowerExport = ' .. PowerExport .. ' W ', dz.LOG_DEBUG)
-- Power consumption
local PowerConsumption = dz.utils.round(PowerGeneration + PowerImport - PowerExport, 0)
dz.log('PowerConsumption = ' .. PowerConsumption .. ' W ', dz.LOG_DEBUG)
-- Energy consumption
local EnergyConsumption = dz.utils.round(EnergyGeneration + EnergyImport - EnergyExport, 0)
dz.log('EnergyConsumption = ' .. EnergyConsumption/1000 .. ' kWh ', dz.LOG_DEBUG)
----------------------------------------------------------------------------------------------------------
-- Debug for negative power consumption
----------------------------------------------------------------------------------------------------------
if PowerConsumption < 0 then
dz.log('(NEGATIVE) PowerConsumption = PowerGeneration + PowerImport - PowerExport', dz.LOG_ERROR)
dz.log('' .. PowerConsumption .. ' W = ' .. PowerGeneration .. ' W + ' .. PowerImport .. ' W - ' .. PowerExport, dz.LOG_ERROR)
else
dz.log('PowerConsumption = PowerGeneration + PowerImport - PowerExport', dz.LOG_INFO)
dz.log('' .. PowerConsumption .. ' W = ' .. PowerGeneration .. ' W + ' .. PowerImport .. ' W - ' .. PowerExport, dz.LOG_INFO)
end
----------------------------------------------------------------------------------------------------------
-- Update device
----------------------------------------------------------------------------------------------------------
Consumption.updateElectricity(PowerConsumption, EnergyConsumption)
end
}
Re: Timing challenge
Posted: Monday 20 July 2020 10:51
by roblom
I think trade is a "bug" in the code but am not sure how to solve it. When the PV doesn't update anymore I think the historical data check
dz.data.PowerGenerationHistory.size>3 isn't true anymore after 4 minutes after the PV system went off. So I think the "return" causes that the consumption isn't updated anymore.
What if I change the "maxMinutes = 4" to a max size? I assume then the history isn't deleted, is that correct?
Verstuurd vanaf mijn ELE-L29 met Tapatalk
Re: Timing challenge [Solved]
Posted: Monday 20 July 2020 11:15
by waaren
roblom wrote: Monday 20 July 2020 10:51
I think trade is a "bug" in the code but am not sure how to solve it. When the PV doesn't update anymore I think the historical data check
dz.data.PowerGenerationHistory.size>3 isn't true anymore after 4 minutes after the PV system went off. So I think the "return" causes that the consumption isn't updated anymore.
If the solarPanels stop reporting at a certain time or when they do not produce anything then change
line 46 from
Code: Select all
PowerGenerationHistory = { history = true, maxMinutes = 4 },
to
Code: Select all
PowerGenerationHistory = { history = true, maxItems = nn },
Where nn is approx. the amount of samples you would have in 4 minutes during normal operation
What if I change the "maxMinutes = 4" to a max size? I assume then the history isn't deleted, is that correct?
History will be deleted when "max size" is hit. You don't want that because it will create performance issues