Update daily gas usage

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Joep123
Posts: 56
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Update daily gas usage

Post by Joep123 »

I use script below to update a custom sensor to monitor my daily gas usage based on degree days. It works fine.
Actually I want to use a gas sensor (or a RFX sensor). I tried to update these sensors with

Code: Select all

domoticz.devices('Gas per graaddag').updateGas(GasUsageperDegreesday)
but then the gas counter will be updated in stead of the daily usage.

Can anyone help me to update the daily usage?

Code: Select all

return {
          on   = { timer    = { "at 23:58"}},

  execute = function(domoticz)
        local Date = domoticz.time.year..domoticz.time.month..domoticz.time.day
        local meantempOutside = domoticz.devices('Gemiddelde Temp buiten').temperature
        local baseTemp = 18
        local factor = 1
        local degreesday = baseTemp - meantempOutside
        if (domoticz.time.month >= 4 and domoticz.time.month <= 9) then factor = 0.8 end
        if (domoticz.time.month >= 11 or domoticz.time.month <= 2) then factor = 1.1 end
        degreesdays = degreesday * factor
        local GasUsage = domoticz.devices('Gas').counterToday
        local GasUsageperDegreesday = domoticz.round((GasUsage / degreesdays),3)
        if (degreesday <= 0) then 
            degreesdays = 0 
            GasUsageperDegreesday = 0
        end
        domoticz.log('Gemiddelde temperatuur buiten (laatste 24u): '..meantempOutside)
        domoticz.log('Gasverbruik vandaag: '..GasUsage..' m3')
        domoticz.log('Aantal graaddagen: '..degreesdays)
        domoticz.log('Gasverbruik: '..GasUsageperDegreesday..' m3 per graaddag')
        
        domoticz.devices('Gas per graaddag').updateCustomSensor(GasUsageperDegreesday)

  end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Update daily gas usage

Post by waaren »

Joep123 wrote: Wednesday 31 October 2018 18:47 I use script below to update a custom sensor to monitor my daily gas usage based on degree days. It works fine.
Actually I want to use a gas sensor (or a RFX sensor). I tried to update these sensors with

Code: Select all

domoticz.devices('Gas per graaddag').updateGas(GasUsageperDegreesday)
but then the gas counter will be updated in stead of the daily usage.
Can anyone help me to update the daily usage?
@Joep123, the daily usage of a domoticz gas sensor is a calculated value. In the database only the total is stored and domoticz "knows" the total amount at 0:00 (from another table)

select ID,Name,sValue from deviceStatus where id = 36;
ID|Name|sValue
36|Gas|2113123

select * from meter_calendar where deviceRowid=36 and Date=date("now","-1 day") ;
DeviceRowID|Value|Counter|Date
36|3427|2109548|2018-10-30

2113123
2109548 -
3575
Gas meter (36)
Gas meter (36)
gas.png (24.65 KiB) Viewed 1416 times
So trying to store GasUsageperDegreesday in a gas sensor device is not going to give you the information you want to see.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Joep123
Posts: 56
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Update daily gas usage

Post by Joep123 »

Thanks for your clear post Waaren.

I guess a RFX Meter (type gas) will be the same?
I'm looking for a nice way the store GasUsageperDegreesday into a chart (like gas, energy).
hendrikenrenny
Posts: 18
Joined: Monday 20 April 2015 21:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Update daily gas usage

Post by hendrikenrenny »

Hi,

The script is running perfectly and everyday I get the m3/graaddag. I used the script on ehoco.nl.

However, the dummy sensor m3/graaddag doesnot generate a report as you can see with every sensor (eg electricity), where it is reported per day/month the m3/graaddag.

Does anybody know how-to do that?

Second question: the sensor does produce a graph, but it is a line graph where I would prefer a bar. Do you have suggestions how to change that?

Thanks,
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest