I've got a script for door sensors, I'd like to have one block handle all of the door sensors using wildcards since the naming convention is the same, example:
commandArray = {}
if (devicechanged['BackDoorSwitch (Sensor)'] == 'Open' and otherdevices['Security Switch'] == 'Armed') then
commandArray['SendNotification']='Security Alert! Back Door has been opened!#2'
elseif (devicechanged['BackDoorSwitch (Sensor)'] == 'Open' and otherdevices['Security Switch'] == 'Armed Home') then
commandArray['SendNotification']='Security Alert! Back Door has been opened!#2'
end
return commandArray
can I modify this to look for all sensors named *DoorSwitch and then send an alert with the name of whatever door or is tripped?
wildcards in lua
Moderator: leecollings
-
- Posts: 8
- Joined: Friday 20 January 2017 21:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: wildcards in lua
If your DoorSwitch are called, BackDoorSwitch, FrontDoorSwitch, ... etc. then this will check each device changed and if the last 10 letters are DoorSwitch (same spelling same cases) then it will do the standard logic:hmjgriffon wrote:I've got a script for door sensors, I'd like to have one block handle all of the door sensors using wildcards since the naming convention is the same, example:can I modify this to look for all sensors named *DoorSwitch and then send an alert with the name of whatever door or is tripped?Code: Select all
commandArray = {} if (devicechanged['BackDoorSwitch (Sensor)'] == 'Open' and otherdevices['Security Switch'] == 'Armed') then commandArray['SendNotification']='Security Alert! Back Door has been opened!#2' elseif (devicechanged['BackDoorSwitch (Sensor)'] == 'Open' and otherdevices['Security Switch'] == 'Armed Home') then commandArray['SendNotification']='Security Alert! Back Door has been opened!#2' end return commandArray
Code: Select all
commandArray = {}
tc=next(devicechanged)
v=tostring(tc)
if v:sub(-10) == 'DoorSwitch' then
doorname = v:sub(1,-11)
if (devicechanged[v] == 'Open' and otherdevices['Security Switch'] == 'Armed') then
commandArray['SendNotification']='Security Alert! '..doorname..' Door has been opened!#2'
elseif (devicechanged[v] == 'Open' and otherdevices['Security Switch'] == 'Armed Home') then
commandArray['SendNotification']='Security Alert! '..doorname..' Door has been opened!#2'
end
end
return commandArray
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Who is online
Users browsing this forum: No registered users and 1 guest