Rate of change

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

Moderator: leecollings

Post Reply
dezmod
Posts: 6
Joined: Thursday 28 January 2016 16:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Rate of change

Post by dezmod »

Hi all
Looking to monitor the rate of change of a temperature sensor. I would assume you would deduct current temperature reading from previous reading, and then write to a variable But not quite sure how to achieve this is dzvents. Still quite new to scripting.

Thanks in advance

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

Re: Rate of change

Post by waaren »

dezmod wrote: Sunday 06 June 2021 15:01 Looking to monitor the rate of change of a temperature sensor. I would assume you would deduct current temperature reading from previous reading.
Something like below?

Code: Select all

return
{
    on =
    {
        devices =
        {
            'tRate', -- your temperature sensor
        },
    },

   data =
   {
       lTemperature =
       {
            initial = 0,
       },

        tDelta =
        {
            history = true,
            maxHours = 10,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'temperature_rate',
    },

    execute = function(dz, item)
        dz.data.lTemperature = ( item.temperature - dz.data.lTemperature ) / item.lastUpdate.secondsAgo
        dz.data.tDelta.add(dz.data.lTemperature)


        local cstRate = dz.devices(1366) -- custom sensor with X-is label °C / minute
        local rate = dz.utils.round( dz.data.tDelta.avgSince('00:30:00', 0 ), 2 ) 
        
        dz.log('Rate is now ' .. rate .. ' °C / minute over the last 30 minutes.', dz.LOG_DEBUG)
        cstRate.updateCustomSensor( rate )
    end
}
cstRate.png
cstRate.png (17.75 KiB) Viewed 585 times
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dezmod
Posts: 6
Joined: Thursday 28 January 2016 16:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rate of change

Post by dezmod »

Looks good working away this week will look when i get back thank you.
dezmod
Posts: 6
Joined: Thursday 28 January 2016 16:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rate of change

Post by dezmod »

This is working fine thank you. Is there any way to show if the change is negative or positive?
Post Reply

Who is online

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