Page 1 of 1

Wildcards in devicename

Posted: Monday 18 July 2016 11:39
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

Re: Wildcards in devicename

Posted: Monday 18 July 2016 11:58
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

Re: Wildcards in devicename

Posted: Monday 18 July 2016 12:05
by emme
Thanks a lot!!!! :D

this will help a lot! :D :D