Page 1 of 1
Check if value changed
Posted: Thursday 10 September 2020 22:18
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?
Re: Check if value changed
Posted: Thursday 10 September 2020 22:29
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.
Re: Check if value changed [Solved]
Posted: Thursday 10 September 2020 22:39
by Jumper3126
Thanks for that very quick respons waaren!
Re: Check if value changed
Posted: Wednesday 23 September 2020 16:27
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
Re: Check if value changed
Posted: Wednesday 23 September 2020 22:54
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
}
Re: Check if value changed
Posted: Friday 25 September 2020 12:03
by Patricen
Thanks a lot, I'll try this and keep you updated
Re: Check if value changed
Posted: Friday 25 September 2020 14:02
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!