From accumulated to daily heat consumption

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

Moderator: leecollings

Post Reply
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

From accumulated to daily heat consumption

Post by Jan Jansen »

There is a custom sensor that shows the accumulated heat consumption. I would like to add a sensor that shows the heat consumption of the previous day.
heat consumption.png
heat consumption.png (22.89 KiB) Viewed 655 times
I get stuck making the necessary script.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 20:00',
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR, -- change to domoticz.LOG_DEBUG when somesthing is wrong
        marker = 'heat consumption previous day',
    },

        data =
    {
        previousData = { initial = {} }
    },    

    execute = function(dz, timer)

        local totaal = dz.devices('Warmteverbruik totaal')                      -- custom sensor accumulated heat consumption (GJ)
        local gisteren = dz.devices('Warmteverbruik gisteren')                  -- custom sensor heat comsumption previous day (GJ)

        local verschil = totaal.sensorValue - dz.data.previousData
            gisteren.updateCustomSensor(verschil)
            table.insert(dz.data.previousData, totaal.sensorValue)
    end
}
Log shows:

Code: Select all

 2022-01-04 20:00:00.376 Error: dzVents: Error: (3.1.8) heat consumption previous day: An error occurred when calling event handler Warmteverbruik per dag
2022-01-04 20:00:00.376 Error: dzVents: Error: (3.1.8) heat consumption previous day: ...pts/dzVents/generated_scripts/Warmteverbruik per dag.lua:27: attempt to perform arithmetic on a table value (field 'previousData') 
Thanks in advance
vtwp
Posts: 8
Joined: Sunday 06 December 2020 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: From accumulated to daily heat consumption

Post by vtwp »

Hi Jan,

I don't know the solution, but the error message says that it fails performing a numeric calculation because the format of the numbers is not the same ("attempt to perform arithmetic on a table value (field 'previousData')"). That means the error is in the script line:

Code: Select all

local verschil = totaal.sensorValue - dz.data.previousData
Assuming that 'previousData' is a table, maybe you can check how you can call the value from a table. Hope that helps!
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: From accumulated to daily heat consumption [Solved]

Post by Jan Jansen »

@vtwp

Thanks for your reply. By using a uservariable I was able to solve the problem.
Post Reply

Who is online

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