dzVents and $<device> <SOLVED>
Moderator: leecollings
-
nitpicker
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
dzVents and $<device> <SOLVED>
I have a script that turns on the light when a switch is used. After I hide the switch with $switch and changed the script to use idx it doesn't work anymore. Is this a known issue?
Last edited by nitpicker on Monday 05 October 2020 8:51, edited 1 time in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: dzVents and $<device>
It is not a known issue. Can you share the script you used?nitpicker wrote: Friday 02 October 2020 19:42 I have a script that turns on the light when a switch is used. After I hide the switch with $switch and changed the script to use idx it doesn't work anymore. Is this a known issue?
I just tested this with below script and it works as expected using '$hiddenSwitch' and also using the device idx
Code: Select all
return
{
on =
{
devices =
{
-- '$hiddenSwitch', -- both methods ( '$devicename' and idx) do work as expected.
641,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz, item)
dz.log('Device ' .. item.name .. ' triggered this script. State is now ' .. item.state, dz.LOG_DEBUG)
end
}log
- Spoiler: show
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
-
nitpicker
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: dzVents and $<device>
Code: Select all
return
{
on = { devices = { 175, 177 }}, -- Philips Hue dimmer switches
execute = function(dz, item)
local light = dz.devices('Lamp ' .. item.name)
if item.state == 'B1' then
light.switchOn().checkFirst()
elseif item.state == 'B4'then
light.switchOff().checkFirst()
end
end
}When I remove the '$' in front of one of the switches, that one works again as expected.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: dzVents and $<device>
dzVents does not interpret the leading $ as something special. This way of hiding a device is only used in the domoticz GUI.nitpicker wrote: Saturday 03 October 2020 8:39 As soon as I changed the names to idx and hide the devices with the '$' in front of them, it stopped working.
When I remove the '$' in front of one of the switches, that one works again as expected.
So when you code
Code: Select all
local light = dz.devices('Lamp ' .. item.name)Code: Select all
local light = dz.devices('Lamp ' .. '$yourItemName')Below script removes any leading $ from the name before it is used in the assignment of a device to light.
Code: Select all
[code]return
{
on = { devices = { 175, 177 }}, -- Philips Hue dimmer switches
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'unhiding',
},
execute = function(dz, item)
dz.log(item.name .. ' triggered this script',dz.LOG_DEBUG)
local unHiddenName = item.name:gsub('^%p','')
local light = dz.devices('Lamp ' .. unHiddenName)
if item.state == 'B1' then
light.switchOn().checkFirst()
elseif item.state == 'B4'then
light.switchOff().checkFirst()
end
endDebian 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
-
nitpicker
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: dzVents and $<device>
It works, thanks!
So this part: item.name:gsub('^%p','') removes the leading $
So this part: item.name:gsub('^%p','') removes the leading $
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: dzVents and $<device>
Yes. It replace the $ if it is the first character of item.name with an empty string.nitpicker wrote: Sunday 04 October 2020 19:11 So this part: item.name:gsub('^%p','') removes the leading $
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