Page 1 of 1

Temperature last change of value

Posted: Thursday 28 May 2020 17:49
by Opus
Hi,
how can I get the time of the last change of a temperature sensor? Not the last update because this is every time receive datas from sensor, but not the last change of value.

Re: Temperature last change of value

Posted: Thursday 28 May 2020 22:30
by waaren
Opus wrote: Thursday 28 May 2020 17:49 How can I get the time of the last change of a temperature sensor? Not the last update because this is every time receive datas from sensor, but not the last change of value.
The only way to do that in domoticz is to store last changed value somewhere. You could store it in a domoticz variable or in a virtual sensor or in dzVents persistent data.

a dzVents solution for this can be like below script example.

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Internal Temperature', -- change to name of your sensor
        },
    },

    data =
    {
        temperature =
        {
            history = true,
            maxItems = 1,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when working OK
    },


    execute = function(dz, item)
        local currentTemperature = tostring(dz.utils.round(item.temperature,1))

        if dz.data.temperature.size > 0 then
            local lastTemperature = dz.data.temperature.getLatest().data
            local lastTime = dz.data.temperature.getLatest().time

            dz.log('Temperature of Sensor ' .. item.name .. ' was ' .. lastTemperature .. ' at ' .. lastTime.rawDate  .. ' ' .. lastTime.rawTime  , dz.LOG_DEBUG)
            dz.log('Temperature of Sensor ' .. item.name .. ' is now ' .. currentTemperature , dz.LOG_DEBUG)
            if lastTemperature ~=  currentTemperature then
                dz.data.temperature.add(currentTemperature)
            end
        else
            dz.data.temperature.add(currentTemperature)
        end

    end
}

Re: Temperature last change of value

Posted: Monday 15 June 2020 13:56
by Opus
Thank you,

my script in use is written with lua and not the shortest. :? I
I will find a way to integrate your idea.