One script to match multiple devices Topic is solved
Moderator: leecollings
One script to match multiple devices
Hello,
I have about 200 panic buttons connected to my domoticz with mysensors gateways. These are push buttons , but I added every button as a door contact , because of automatic release. I want to send notification when button is pressed and I can make it from notification section of every single one , but I want to make a script that matches all of them and send notifications when button is pressed , 1 script for all. I set the names for example: PANIC - 1 , PANIC - 2 , PANIC - 3 and so on ... And the script have to be something like:
commandArray = {}
if (devicechanged['PANIC ???something*'] == 'Closed') then
commandArray['SendNotification']='.. devicename button pressed'
end
return commandArray
Please anyone help with that.....
I have about 200 panic buttons connected to my domoticz with mysensors gateways. These are push buttons , but I added every button as a door contact , because of automatic release. I want to send notification when button is pressed and I can make it from notification section of every single one , but I want to make a script that matches all of them and send notifications when button is pressed , 1 script for all. I set the names for example: PANIC - 1 , PANIC - 2 , PANIC - 3 and so on ... And the script have to be something like:
commandArray = {}
if (devicechanged['PANIC ???something*'] == 'Closed') then
commandArray['SendNotification']='.. devicename button pressed'
end
return commandArray
Please anyone help with that.....
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: One script to match multiple devices
Something like this?:
Jos
Code: Select all
commandArray = {}
for dev, status in pairs(devicechanged) do
-- Check Panicbutton pressed
if (dev:sub(1, 6) == 'PANIC '] and status == 'Closed') then
commandArray['SendNotification']= dev ..' button pressed'
end
end
return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: One script to match multiple devices
Thank you very much ! Yes , exactly like this , but:jvdz wrote: ↑Monday 15 June 2020 13:19 Something like this?:JosCode: Select all
commandArray = {} for dev, status in pairs(devicechanged) do -- Check Panicbutton pressed if (dev:sub(1, 6) == 'PANIC '] and status == 'Closed') then commandArray['SendNotification']= dev ..' button pressed' end end return commandArray
It returns error for some reason , Domoticz 2020.2
Error: EventSystem: in PANIC Button: [string "commandArray = {} ..."]:4: ')' expected near ']'
-
- Posts: 744
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: One script to match multiple devices
Yes, because of the ] behind the word panic? Please remove.shketiev wrote:Thank you very much ! Yes , exactly like this , but:jvdz wrote: ↑Monday 15 June 2020 13:19 Something like this?:JosCode: Select all
commandArray = {} for dev, status in pairs(devicechanged) do -- Check Panicbutton pressed if (dev:sub(1, 6) == 'PANIC '] and status == 'Closed') then commandArray['SendNotification']= dev ..' button pressed' end end return commandArray
It returns error for some reason , Domoticz 2020.2
Error: EventSystem: in PANIC Button: [string "commandArray = {} ..."]:4: ')' expected near ']'
Re: One script to match multiple devices
I noticed that , and I actually see that I have posted previous error. After I remove ] after PANIC ' the error is on line 2.
Error: EventSystem: in PANIC Button: [string "commandArray = {} ..."]:2: bad argument #1 to 'pairs' (table expected, got nil)
I don't why this error appears (every 60 seconds), but the script actually works and notifications is received correctly.
Error: EventSystem: in PANIC Button: [string "commandArray = {} ..."]:2: bad argument #1 to 'pairs' (table expected, got nil)
I don't why this error appears (every 60 seconds), but the script actually works and notifications is received correctly.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: One script to match multiple devices
You should save the Lua script as triggered on Device. You now probably saved it to be triggered on 'All'
top right corner of the edit window..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: One script to match multiple devices
Re: One script to match multiple devices
Just wondering , how can I add some limiting option for example:
If button is pressed , send notification , but once a minute , or every X time.
Now when someone press the button multiple times , it floods the system
Thanks !
If button is pressed , send notification , but once a minute , or every X time.
Now when someone press the button multiple times , it floods the system

Thanks !
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: One script to match multiple devices
Could look like
Code: Select all
commandArray = {}
local function string2Epoch(dateString, pattern)
local pattern = pattern or '(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)'
local year, month, day, hour, minute, seconds = dateString:match(pattern)
return os.time({year = year, month = month, day = day , hour = hour, min = minute, sec = seconds })
end
for dev, status in pairs(devicechanged) do
if dev:sub(1, 5) == 'PANIC' and status == 'Closed' then
local secondsAgo = os.time() - string2Epoch(otherdevices_lastupdate[dev])
if secondsAgo > 60 then
commandArray['SendNotification']= dev ..' button was pressed before ' .. secondsAgo .. ' seconds Ago'
else
print('No notification send. Last update of ' .. dev .. ' was ' .. secondsAgo .. ' seconds Ago')
end
-- commandArray[#commandArray+1] = {[dev] = 'Open NOTRIGGER'} -- Don't know if this is needed and if so it works. Just try after confirming the other part does work
end
end
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest