Page 1 of 1
dzVents and $<device> <SOLVED>
Posted: Friday 02 October 2020 19:42
by nitpicker
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?
Re: dzVents and $<device>
Posted: Saturday 03 October 2020 1:30
by waaren
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?
It is not a known issue. Can you share the script you used?
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
Code: Select all
devicename hiddenSwitch (without $); dzVents script triggered on 'hiddenSwitch'
----------------------------------------------------------------------------------------------------
2020-10-03 01:12:23.691 Status: User: Admin initiated a switch command (641/hiddenSwitch/On)
2020-10-03 01:12:23.694 (Virtual) Light/Switch (hiddenSwitch)
2020-10-03 01:12:23.790 Status: dzVents: Info: Handling events for: "hiddenSwitch", value: "On"
2020-10-03 01:12:23.791 Status: dzVents: Info: ------ Start internal script: dz 20201003 Hidden: Device: "hiddenSwitch (Virtual)", Index: 641
2020-10-03 01:12:23.792 Status: dzVents: Debug: Device hiddenSwitch triggered this script. State is now On
2020-10-03 01:12:23.794 Status: dzVents: Info: ------ Finished dz 20201003 Hidden
devicename $hiddenSwitch (with $); dzVents script triggered on '$hiddenSwitch'
---------------------------------------------------------------------------------------------
2020-10-03 01:13:00.541 Status: User: Admin initiated a switch command (641/$hiddenSwitch/On)
2020-10-03 01:13:00.551 (Virtual) Light/Switch ($hiddenSwitch)
2020-10-03 01:13:00.798 Status: dzVents: Info: Handling events for: "$hiddenSwitch", value: "On"
2020-10-03 01:13:00.799 Status: dzVents: Info: ------ Start internal script: dz 20201003 Hidden: Device: "$hiddenSwitch (Virtual)", Index: 641
2020-10-03 01:13:00.801 Status: dzVents: Debug: Device $hiddenSwitch triggered this script. State is now On
2020-10-03 01:13:00.803 Status: dzVents: Info: ------ Finished dz 20201003 Hidden
devicename $hiddenSwitch (with $); dzVents script triggered on 641
------------------------------------------------------------------------------
2020-10-03 01:14:00.591 Status: User: Admin initiated a switch command (641/hiddenSwitch/On)
2020-10-03 01:14:00.594 (Virtual) Light/Switch ($hiddenSwitch)
2020-10-03 01:14:00.597 Status: dzVents: Info: Handling events for: "$hiddenSwitch", value: "Off"
2020-10-03 01:14:00.598 Status: dzVents: Info: ------ Start internal script: dz 20201003 Hidden: Device: "$hiddenSwitch (Virtual)", Index: 641
2020-10-03 01:14:00.599 Status: dzVents: Debug: Device $hiddenSwitch triggered this script. State is now Off
2020-10-03 01:14:00.601 Status: dzVents: Info: ------ Finished dz 20201003 Hidden
Re: dzVents and $<device>
Posted: Saturday 03 October 2020 8:39
by nitpicker
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
}
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.
Re: dzVents and $<device>
Posted: Saturday 03 October 2020 9:16
by waaren
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.
dzVents does not interpret the leading $ as something special. This way of hiding a device is only used in the domoticz GUI.
So when you code
Code: Select all
local light = dz.devices('Lamp ' .. item.name)
dzVents does
Code: Select all
local light = dz.devices('Lamp ' .. '$yourItemName')
Unless your light is named Lamp$yourItemName it will no longer be found.
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
end
Re: dzVents and $<device>
Posted: Sunday 04 October 2020 19:11
by nitpicker
It works, thanks!
So this part: item.name:gsub('^%p','') removes the leading $
Re: dzVents and $<device>
Posted: Sunday 04 October 2020 19:27
by waaren
nitpicker wrote: Sunday 04 October 2020 19:11
So this part:
item.name:gsub('^%p','') removes the leading
$
Yes. It replace the $ if it is the first character of item.name with an empty string.