Page 1 of 1

Notification by triggered device

Posted: Tuesday 23 July 2019 21:03
by gewoonandre
Hi all,

Most likely just a basic question, but after reading the documentation, it is still not clear to me what i'm doing wrong :?

I do have multiple motion sensors (Called: Beweging aaa, Beweging bbb, etc) and multiple contact sensors (Called: Deur ccc, Deur ddd, etc). The notification should look like : "Triggered by Deur ccc" or "Triggered by Deur ddd" based on the sensor that triggerd this script.
Probably i can add all sensors locally, but i thought it should also be possible by using "Beweging*" and "*deur" .

When one of the sensors becomes active, the script is triggered (so, that part works at least), but it ends up with an error in the log file.

It looks like the data is not available at the place where i want to show it?
Can somebody explain how/why this is happening? and what i can do to fix it.

Code: Select all

An error occurred when calling event handler 
2019-07-23 20:58:06.289 Error: dzVents: Error: (2.4.26) Deur/Beweging - : ...i/domoticz/scripts/dzVents/generated_scripts/Alarm01.lua:15: attempt to index field 'data' (a nil value)

The script :

Code: Select all

return {
    on = {
        devices = {
            "*deur",
            "Beweging*"
        },
    },
        
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "Deur/Beweging - " },
    
    execute = function(dz, triggeredItem, info)
  
        if (triggeredItem.active) then       -- state == 'On'
			dz.notify('info', 'The item ' .. dz.data.triggeredItem.name .. ' was triggered')
			dz.notify("Domoticz", 'Device : ' ..dz.data.triggeredItem.name .. ' << item that triggered this ', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , "telegram")
		end
        
    end
}
Thanks in advance!

Re: Notification by triggered device

Posted: Tuesday 23 July 2019 21:19
by EddyG
Should it not be:

Code: Select all

        devices = {
            "Deur*",
            "Beweging*"
        },

Re: Notification by triggered device

Posted: Tuesday 23 July 2019 21:49
by waaren
gewoonandre wrote: Tuesday 23 July 2019 21:03 Most likely just a basic question, but after reading the documentation, it is still not clear to me what i'm doing wrong :?
I don't understand why you use dz.data. You have not defined a data section so you probably want something like

Code: Select all

return {
    on = {
        devices = {
            "*Deur*",
            "*Beweging*"
        },
    },
        
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "Deur/Beweging - " },
    
    execute = function(dz, item)
  
        if item.active then       -- state == 'On'
			dz.notify('info', 'The item ' .. item.name .. ' was triggered')
			dz.notify("Domoticz", 'Device : ' .. item.name .. ' << item that triggered this ', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, nil , dz.NSS_TELEGRAM)
		end
    end
}

Re: Notification by triggered device  [Solved]

Posted: Tuesday 23 July 2019 21:56
by gewoonandre
Thanks a lot @waaren.
That did the job! Its working now.

I used another example script that i've modified myself (wrongly offcourse)...Therefore the dz.data was still there.