Hi,
I have some selector switches by wich events will be executed or not, depending on its state.
Sometimes, multiple states may be executed but then i need to combine levels in new levels, like: level10= x, level20= y, level30= z, level40= x+y, level50= x+y+z, level60= y+z, level70= x+z. In my dzVents scripts i have to use string.match on the selector switch.state, wich does not always work witch symbols like ":" and "()".
Therefore it would be usefull if i could just enable the levels that need to be executed and then use somthing like <multiselectorswitch.level('x').active == true> in my scripts. I would also need less levels in my selector switch.
Or does something similar already exists?
Thx,
Jimmy
Multiple choice selector switch
Moderators: leecollings, remb0
-
- Posts: 16
- Joined: Thursday 28 November 2019 0:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Belgium
- Contact:
Multiple choice selector switch
RPI4, Philips Hue, Tradfri, Sonoff, MQTT, Zigbee2Mqtt, RFXCom 433, Octoprint,...
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Multiple choice selector switch
Would indeed be nice to have such a device but unfortunately it does not exist in domoticz and if I understand the underlying code for devices correctly, I don't think it will be very easy to implement either. In other words: don't hold your breath until it is implemented.
Until then I am happy to see if I can help to overcome the problem with string.match and identify which states are active when combined.
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
-
- Posts: 16
- Joined: Thursday 28 November 2019 0:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Belgium
- Contact:
Re: Multiple choice selector switch
Thanks for your fast reply and sorry for my late answer

I worked arround this by renaming my devices, so i don't need string.match anymore in this case. But maybe for your interest, here's what went wrong:
Deur Kelder MK => triggered device.name
Deur Kelder MK => selectorswitch.state
Deur Kelder MK => output of string.match(selectorswtich.state,device.name)
Deur Kelder (MK) => triggered device.name
Deur Kelder (MK) => selectorswitch.state
nil => output of string.match(selectorswtich.state,device.name)
So, the "()" in the name of a device (or maybe any string) always output "NIL" with string.match.
Similar issue when using wildcards in the on-section. If i use for exemple: on = *(MK)*, other devices with "MK" (without the -()-) also get triggered.
Another issue with symbols i ran into, are the ":". Dazzled me for hours

A device holding ":" in it's name, doesn't get switched, no errors logged. I removed the ":" in the devicename and the problem was solved.
In the beginning, i used Blockly for these few scripts and they worked fine, but since they were getting to complicated i wrote them in dzVents. Therefore, i could not understand why it would not work.
Now i know i have to avoid using symbols in names

Thx,
Jimmy
RPI4, Philips Hue, Tradfri, Sonoff, MQTT, Zigbee2Mqtt, RFXCom 433, Octoprint,...
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Multiple choice selector switch
Thx for getting back to me and reporting what caused some of your issues. I need to investigate the unexpected behavior in more detail but if I can modify dzVents to make it more reliable for this I will.
The () are so called magic chars in Lua pattern matching and that's why your match result is not what you expected. One way to work around this is the use of a 'sanitized' string.match function. (see below)
Code: Select all
local function string.sMatch(text, match) -- add sanitized match function to string "library"
local sanitizedMatch = match:gsub("([%%%^%$%(%)%.%[%]%*%+%-%?])", "%%%1") -- escaping all 'magic' chars
return text:match(sanitizedMatch)
end
print(string.sMatch(selectorswitch.state,device.name))
Deur Kelder (MK)
-- or
print(selectorswitch.state:sMatch(device.name))
Deur Kelder (MK)
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