Page 1 of 1

Rate of change

Posted: Sunday 06 June 2021 15:01
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

Re: Rate of change

Posted: Sunday 06 June 2021 21:54
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 744 times

Re: Rate of change

Posted: Monday 07 June 2021 12:43
by dezmod
Looks good working away this week will look when i get back thank you.

Re: Rate of change

Posted: Saturday 17 July 2021 18:26
by dezmod
This is working fine thank you. Is there any way to show if the change is negative or positive?