Page 1 of 1

Question regarding dzvents triggers

Posted: Thursday 20 September 2018 14:42
by dzdm
Hi all,

I have some questions regarding dzvents triggers:

(TestDev is a Switch)

1. Will a on = { devices = { 'TestDev' } } be triggered when the device is on and a state change on->on occurs (yes, on to on)?

The background is, that I have a device which can be on or off. Additionally, it sends periodic status reports, so it is possible that there will be a on->on state change.

2. Does a domoticz switch item have a lastState flag?

3. changed: Boolean. True if the device was changed -> When exactly will this be set?


Thank you :)

Re: Question regarding dzvents triggers

Posted: Thursday 20 September 2018 15:44
by SweetPants
dzdm wrote: Thursday 20 September 2018 14:42
1. Will a on = { devices = { 'TestDev' } } be triggered when the device is on and a state change on->on occurs (yes, on to on)?
As far as I know yes. I use a dummy switch for each phone detected and reset a lastupdate timer for each phone if it is (re)detected again.

Re: Question regarding dzvents triggers

Posted: Thursday 20 September 2018 16:48
by waaren
dzdm wrote: Thursday 20 September 2018 14:42 I have some questions regarding dzvents triggers:

(TestDev is a Switch)
1. Will a on = { devices = { 'TestDev' } } be triggered when the device is on and a state change on->on occurs (yes, on to on)?
2. Does a domoticz switch item have a lastState flag?
3. changed: Boolean. True if the device was changed -> When exactly will this be set?
1. Yes (see test script below)
2. No. Previous states of switches are only kept in the history tables. dzVents can store it in persistent data (see test script below)
nb. a dimmer does store it's last dimlevel
3. Not sure what you mean here. Please elaborate a bit on the case where you want it for.

Code: Select all

return {
    on = { devices = { "TestDev"}}  ,

    data    =   { previousState = { initial = "initialized" } },

    execute = function(dz, item)

        dz.log(item.name .. " ==>  state:  " .. item.state .. "; previous state: " .. dz.data.previousState)
        dz.data.previousState = item.state
        
    end
}