extrapolate / calculate values from counters in LUA

Moderator: leecollings

Post Reply
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

extrapolate / calculate values from counters in LUA

Post by dervogt »

Hi to all,

I am long time user of domoticz and now starting to develop my own concepts for LUA scripting as this is the only way to make calculations based on device values in Domoticz, at least to my understanding.

I'd actually like to calculate the energy consumption of my city heating (Stadswarmte) installationwithout the need to install or tap off additional input signals from the heatmeter as these are all sealed and impossible to access. Reading out the meter via IR of course would be the superior solution but due to multiple factors (money, sealed meter) this is not possible right now, so thought I can calculate the energy consumption based on already available values.

I got available:
Heating temperature out (Voorlooptemperatuur) which is a constant 52 degrees
Heating temperature in (Teruglooptemperatuur) which is mostly around 41 degrees and due to city warming, quite stable
The circulation pump flow, 490 liters per hour
Delta temp out/in 9 degrees
to heat one kg/liter of water by one degree, we usually require 0.12 kwh of energy, so the conclusion is, that the delta temp of 9 degrees makes 0.0108 kwh of heat loss per liter water running through the heating radiators when the heating is switched on.

Calculated on a (peak) flow of 490 liter water per hour running through our city heating system, this would equal up to 5.292 kwh in an hour.
Converting this to GigaJoule (the unit with which my heatmeter measures) this brings up the consumption of the heating system to 0.0003175 gigaJoule per minute in case the circulation pump is switched on.

My idea is, to setup a counter device which will be fed by another dummy counter registering the runtime of the circulation pump, then multiplying the runtime of the pump with the specific energy usage as explained above and then write the energy consumption via LUA script into the final counter device.

Currently I am struggling with the syntax in LUA, I am using an LUA with the below syntax to read the status of the heating pump, add an incremental counter and then multiply this result by the specific usage in GJ, then write the result of this calculation into the dummy counter device:

Code: Select all

local timer_device_ID = 126

commandArray = {}

local TotalMinutesOn = otherdevices_svalues['Stadswarmte Verbruik']
if otherdevices['Circulatiepomp'] == 'On' then
  TotalMinutesOn = ((TotalMinutesOn + 1)* 0.0003175)
end
commandArray['UpdateDevice'] = timer_device_ID .. '|0|' .. tostring(TotalMinutesOn)

return commandArray
Writing into the counter works well, but with the unwanted side-effect, that the counter always counts a full gigajoule and not the actual usage:

126 Stadswarmte Verbruik 0.00031760083826615 2017-03-09 16:14:06 0.00031760083826615

I have setup a counter device with the following settings:
Naam:
Stadswarmte Verbruik
Omschrijving:
Type:
Meter Offset:
0
Waarde hoeveelheid (bijvoorbeeld gewicht):
Gigajoule
Waarde Units ( bijvoorbeeld Kg ):
Gigajoule
every update of the counter results in the counter counting a full gigajoule in place of the minute value.

Anyone a smart idea on what I am doing wrong here?
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

Re: extrapolate / calculate values from counters in LUA

Post by dervogt »

I made some progress since yesterday, now I am able to do the calulation in the script and write this to a custom sensor in Domoticz, this is my current LUA code:

Code: Select all

local timer_device_ID = 126
local TotalMinutesOn = otherdevices_svalues['Circulatiepomp Timer']
 
commandArray = {}
 
if otherdevices['Circulatiepomp'] == 'On' then
  TotalMinutesOn = (((TotalMinutesOn + 1)* 0.0003175)/1000) --calculate the energy usage in GigaJoule per minute runtime
  commandArray['UpdateDevice'] = timer_device_ID .. '|0|' .. tostring(TotalMinutesOn) --write the calculation to the Custom Sensor
  parseDebug = ('Calculated value Stadswarmte=' .. tostring(TotalMinutesOn)) --compile debug line for Domo-log
  print (print(parseDebug)) --print debug line to Domo log
end
 
if otherdevices['Circulatiepomp'] == 'Off' then --if pump not working, do nothing
    print ('Stadswarmte no usage update necessary')
end
return commandArray

This gives me a nice calculation from the heating usage and currently writes this into a custom sensor:

Image

The only challenge I got is, that I actually want to have it look like the P1 Smart Meter counter charts, which does not seem to be possible with the script right now.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest