trigger on counter not selective :-(

Moderator: leecollings

Post Reply
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

trigger on counter not selective :-(

Post by freijn »

Guys, can you please help me understanding.

I have 3 counters as listed below with individual idx's 87, 99 and 98

I would like to get a notification when the 99 or 98 counter does get incremented however it I enable the below Lua I do get notifications from the idx 87
as well, more over incremented the idx 87 by 1 give an notification of 98 and 99 at the same time.
I am sure I am missing something.. please advice.

Thanks in advantage , Frank

Code: Select all

commandArray = {}
if (devicechanged['Police HeliCopter 10Km']) then
    commandArray['SendNotification']='Police Heli in the Air!'
end

if (devicechanged['LifeLiner Rescue 10Km']) then
    commandArray['SendNotification']='LifeLiner Heli in the Air!'
end


return commandArray
Attachments
Capture.JPG
Capture.JPG (66.54 KiB) Viewed 782 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: trigger on counter not selective :-(

Post by waaren »

freijn wrote: Wednesday 24 April 2019 20:22 I have 3 counters as listed below with individual idx's 87, 99 and 98
I would like to get a notification when the 99 or 98 counter does get incremented however it I enable the below Lua I do get notifications from the idx 87
as well, more over incremented the idx 87 by 1 give an notification of 98 and 99 at the same time.
I am sure I am missing something.. please advice.
If I look at "laatst gezien" all your counters got updated at the same second. Are they updated by a plugin or script ?
Please note that devicechanged["name"] will return true when the lastUpdate field is updated. This does not necessarily mean the value of the counter has changed.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: trigger on counter not selective :-(

Post by freijn »

waaren wrote: Wednesday 24 April 2019 20:56 If I look at "laatst gezien" all your counters got updated at the same second. Are they updated by a plugin or script ?
Please note that devicechanged["name"] will return true when the lastUpdate field is updated. This does not necessarily mean the value of the counter has changed.
Thas is correct, all updated from the same script.
Is there not an event possible when the counter get's incremented ?
Do I need to store the counter value in an variable and compare that every minute for the change?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: trigger on counter not selective :-(

Post by waaren »

freijn wrote: Wednesday 24 April 2019 21:06 Do I need to store the counter value in an variable and compare that every minute for the change?
That is an option but My preference would be to use dzVents persistent var for this.

It could look like:

Code: Select all

return {
            on =    {
                    devices = { 'Police HeliCopter 10Km', 
                                'LifeLiner Rescue 10Km' ,
                              },
                    },

    data =  {
                PoliceCounter = { initial = 0 },
                LifeLinerCounter = { initial = 0 },
            },

    logging =   {
                    level = domoticz.LOG_DEBUG,
                    marker = "Heli counter"
                },

    execute = function(dz, item)
        if item.name == 'Police HeliCopter 10Km' and item.counter ~= dz.data.PoliceCounter then
            dz.notify('Air alert','Police Heli in the Air!')
            dz.data.PoliceCounter = item.counter
        elseif item.name == 'LifeLiner Rescue 10Km' and item.counter ~= dz.data.LifeLinerCounter then
            dz.notify('Air alert','LifeLiner Heli in the Air!')
            dz.data.LifeLinerCounter = item.counter
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: trigger on counter not selective :-(

Post by freijn »

Waaren

Thanks for the script ! Set it in production.. now wait till the Heli fly over.

(to speed up I could make a phone call :-) )
no no, just a joke


.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: trigger on counter not selective :-(

Post by freijn »

Waaren

Thanks !!!!
Attachments
Capture.JPG
Capture.JPG (14.51 KiB) Viewed 764 times
Capture.JPG
Capture.JPG (50.05 KiB) Viewed 764 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest