dzVents and $<device> <SOLVED>

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

dzVents and $<device> <SOLVED>

Post 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?
Last edited by nitpicker on Monday 05 October 2020 8:51, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents and $<device>

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
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>

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents and $<device>

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
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>

Post by nitpicker »

It works, thanks!

So this part: item.name:gsub('^%p','') removes the leading $
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents and $<device>

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest