Check if value changed  [Solved]

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

Moderator: leecollings

Post Reply
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Check if value changed

Post by Jumper3126 »

the lastupdate feature of DZventz is enormously handy, but for a new script I would like to know when a device (integer value) has changed. This specific devices is updated every minute but also if the value didn't change. Is this possible somehow or do i need to work with persistent data to store and compare?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check if value changed

Post by waaren »

Jumper3126 wrote: Thursday 10 September 2020 22:18 the lastupdate feature of DZventz is enormously handy, but for a new script I would like to know when a device (integer value) has changed. This specific devices is updated every minute but also if the value didn't change. Is this possible somehow or do i need to work with persistent data to store and compare?
Yes you need to work with persistent data or a domoticz uservariable to compare current state with a previous state if your device is not a dimmer or selector. For these types you can use the lastLevel attribute.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Check if value changed  [Solved]

Post by Jumper3126 »

Thanks for that very quick respons waaren!
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Check if value changed

Post by Patricen »

Hello,
This looks like it could solve my issue. I would like to trigger an event on sudden dewpoint rise. Do you have any example showing this?
using my algorithmic language it would look like
If sensor above stove's dewpoint rose more than 1°C since last update
Set cooker hood to "on"
Thanks
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Check if value changed

Post by waaren »

Patricen wrote: Wednesday 23 September 2020 16:27 This looks like it could solve my issue. I would like to trigger an event on sudden dewpoint rise. Do you have any example showing this?
Something like below ?

Code: Select all

return 
{
    on =
    {
        devices = 
        {
            'myDewpointSensor', -- change to name of Sensor
        },
    },
    
    data =
    {
        lastValue =
        {
            initial = 0,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
        marker = 'dewPoint-rise',
    },

    execute = function(dz, item)
        cookerHood = dz.devices('cooker hood') -- change to name of Cooker Hood device
        
        dz.log('\nDevicename: ' .. item.name .. ', nValue: ' .. item.nValue .. ', sValue: ' .. item.sValue .. 
               '\nDevicetype: ' .. item.deviceType .. ', deviceSubType: ' .. item.deviceSubType .. 
               '\nlastValue: ' .. dz.data.lastValue, dz.LOG_DEBUG )

        if item.dewPoint >=  dz.data.lastValue + 1 then     
            cookerHood.switchOn().checkFirst()
        end
        if dz.data.lastValue ~= item.dewPoint then
            dz.data.lastValue = item.dewPoint
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Check if value changed

Post by Patricen »

Thanks a lot, I'll try this and keep you updated
Patricen
Posts: 121
Joined: Tuesday 06 February 2018 18:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta rel
Contact:

Re: Check if value changed

Post by Patricen »

waaren wrote: Wednesday 23 September 2020 22:54
Patricen wrote: Wednesday 23 September 2020 16:27 This looks like it could solve my issue. I would like to trigger an event on sudden dewpoint rise. Do you have any example showing this?
Something like below ?

Code: Select all

return 
{
    on =
    {
        devices = 
        {
            'myDewpointSensor', -- change to name of Sensor
        },
    },
    
    data =
    {
        lastValue =
        {
            initial = 0,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
        marker = 'dewPoint-rise',
    },

    execute = function(dz, item)
        cookerHood = dz.devices('cooker hood') -- change to name of Cooker Hood device
        
        dz.log('\nDevicename: ' .. item.name .. ', nValue: ' .. item.nValue .. ', sValue: ' .. item.sValue .. 
               '\nDevicetype: ' .. item.deviceType .. ', deviceSubType: ' .. item.deviceSubType .. 
               '\nlastValue: ' .. dz.data.lastValue, dz.LOG_DEBUG )

        if item.dewPoint >=  dz.data.lastValue + 1 then     
            cookerHood.switchOn().checkFirst()
        end
        if dz.data.lastValue ~= item.dewPoint then
            dz.data.lastValue = item.dewPoint
        end
    end
}

Waahh!! Brilliant, this works like a charm, thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest