Wildcards in devicename

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Wildcards in devicename

Post by emme »

Ciao,

Is there a way to use wildards in sensors/Switches name in scripts?

I have 4 PIR sensors all names PIR_ and a blocky script that take action base don security level
actually I have to add few IF PIR_Sala = ON OR PIR_Camera = on .... etc etc.


but I was wondering if it's possibile to use something like.... if PIR_* = ON Then....

I tried in LUA, but of course it wasn't succesful :P
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
simonrg
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 devicename

Post by simonrg »

emme wrote:Is there a way to use wildards in sensors/Switches name in scripts?
Absolutely - basically use substring to only compare the characters you want to, so for the code below, only when the devicechanged starts with PIR_ will the if block be executed:

Code: Select all

tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,4) == 'PIR_') then
    -- do something
end
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
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Wildcards in devicename

Post by emme »

Thanks a lot!!!! :D

this will help a lot! :D :D
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest