Notification by triggered device  [Solved]

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

Moderator: leecollings

Post Reply
gewoonandre
Posts: 4
Joined: Monday 24 April 2017 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10935
Location: Netherlands, OV
Contact:

Notification by triggered device

Post 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!
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Notification by triggered device

Post by EddyG »

Should it not be:

Code: Select all

        devices = {
            "Deur*",
            "Beweging*"
        },
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification by triggered device

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gewoonandre
Posts: 4
Joined: Monday 24 April 2017 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10935
Location: Netherlands, OV
Contact:

Re: Notification by triggered device  [Solved]

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest