How to control with a Selector Switch (zigbee device)  [Solved]

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

Moderator: leecollings

Post Reply
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How to control with a Selector Switch (zigbee device)

Post by gschmidt »

Hi,

I recently bought a zigbee TuYa wireless wall switch (2 buttons).
The domoticz-zigbee2mqtt-plug-in has created a Selector Switch with 6 levels (1_single, 1_double, 1_hold, 2_single, 2_double, 2_hold)
Each button has 3 actions (single click, double click and long press)

I want create a script which e.g. clicking "1_single", turns a group or device ON and clicking "1_double" turns this group or device OFF
Does anyone has an example ho to approach this?
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by waltervl »

It is easier to toggle the group with only 1_single.
You can do this with a dzvents script. It can check the status of the group and then toggle it on or off.

See for example viewtopic.php?t=25062
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
lxh7
Posts: 3
Joined: Monday 14 December 2020 18:34
Target OS: Linux
Domoticz version:
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by lxh7 »

I had to add 4 Selector Levels (per switch): Off, Click, Hold, Release. Then in the event handler you can check the level
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by waaren »

gschmidt wrote: Monday 14 December 2020 19:49 The domoticz-zigbee2mqtt-plug-in has created a Selector Switch with 6 levels (1_single, 1_double, 1_hold, 2_single, 2_double, 2_hold)
I want create a script which e.g. clicking "1_single", turns a group or device ON and clicking "1_double" turns this group or device OFF
Does anyone has an example how to approach this?
Below script could be a solution for this

Code: Select all

local ZSelector = 'Zigbee selector' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('testGroup1')
        local device_2 = dz.devices('testDevice2')

        local Z =
        {-- levelname    targetDevice, action, delay, level   -- delay and level are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },
            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'dimTo', 12, 60 },
            ['2_hold'] = { device_2, 'dimTo', 0, 10 } -- when level is set and no delay the delay should be set to 0
        }

        -- No changes required below this line
        local function switch(object, action, delay, level)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(level).afterSec(delay) -- dimTo not available to groups
            else
                dz.log('unknown action (' .. action ..') please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] )

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by gschmidt »

waaren wrote: Monday 14 December 2020 21:12
gschmidt wrote: Monday 14 December 2020 19:49 The domoticz-zigbee2mqtt-plug-in has created a Selector Switch with 6 levels (1_single, 1_double, 1_hold, 2_single, 2_double, 2_hold)
I want create a script which e.g. clicking "1_single", turns a group or device ON and clicking "1_double" turns this group or device OFF
Does anyone has an example how to approach this?
Below script could be a solution for this
Thanx for the example script!
However, the following error is repeatedly shown (also when no action is performed) in the LOG:

Code: Select all

2020-12-14 22:16:34.803 Error: dzVents: Error: (3.0.18) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2020-12-14 22:16:34.803 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:28: '}' expected (to close '{' at line 27) near '_single'
What is
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by waaren »

gschmidt wrote: Monday 14 December 2020 22:25 However, the following error is repeatedly shown (also when no action is performed) in the LOG:

Code: Select all

2020-12-14 22:16:34.803 Error: dzVents: Error: (3.0.18) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2020-12-14 22:16:34.803 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:28: '}' expected (to close '{' at line 27) near '_single'
OK, my bad.. Lua does not like the keys to start with a number. Can you try again after changing the Z table declaration to

Code: Select all

        local Z =
        {-- levelname    targetDevice, action, delay, level   -- delay and level are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },
            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'dimTo', 12, 60 },
            ['2_hold'] = { device_2, 'dimTo', 0, 10 } -- when level is set and no delay the delay should be set to 0
        }
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control a Selector Switch (zigbee device)

Post by gschmidt »

waaren wrote: Monday 14 December 2020 22:30
gschmidt wrote: Monday 14 December 2020 22:25 However, the following error is repeatedly shown (also when no action is performed) in the LOG:

Code: Select all

2020-12-14 22:16:34.803 Error: dzVents: Error: (3.0.18) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2020-12-14 22:16:34.803 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:28: '}' expected (to close '{' at line 27) near '_single'
OK, my bad.. Lua does not like the keys to start with a number. Can you try again after changing the Z table declaration to

Code: Select all

        local Z =
        {-- levelname    targetDevice, action, delay, level   -- delay and level are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },
            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'dimTo', 12, 60 },
            ['2_hold'] = { device_2, 'dimTo', 0, 10 } -- when level is set and no delay the delay should be set to 0
        }
Works like a charm (only a small error you forgot the () after switchOn)

Code: Select all

elseif action == 'On' then object.switchOn.afterSec(delay)
Thanx for the example, I know how to approach this now
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

If my device is a RGBW dimmer what functions need to be added to control the Color and White?

Code: Select all

local function switch(object, action, delay, level)
So lets say under ['1_hold'] I want to set the RGB color to setRGB(255,0,0) and dimto level 70
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by waaren »

gschmidt wrote: Tuesday 15 December 2020 21:02 If my device is a RGBW dimmer what functions need to be added to control the Color and White?
Can you test this one?

Code: Select all

local ZSelector = 'Zigbee selector' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('testGroup1')
        local device_2 = dz.devices('testDevice2')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
                                                    -- R,  G,  B, dimlevel
            ['1_hold'] = {device_2, 'setColor', 0,   { 255, 0, 0, 70 } },
            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'dimTo', 12, 60 },
            ['2_hold'] = { device_2, 'dimTo', 0, 10 } -- when level is set and no delay the delay should be set to 0
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

waaren wrote: Tuesday 15 December 2020 23:39
gschmidt wrote: Tuesday 15 December 2020 21:02 If my device is a RGBW dimmer what functions need to be added to control the Color and White?
Can you test this one?
Thanx man, this script is working (I have changed the order of the selector buttons a bit, and set the color to green):

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('Kerstverlichting')
        local device_2 = dz.devices('Woonkamer_Licht')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },

            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'Off' },
                                                   -- R,  G,  B, dimlevel
            ['2_hold'] = {device_2, 'setColor', 0,   { 0, 255, 0, 70 } },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}
This is the Log:

Code: Select all

2020-12-16 20:02:23.161 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-12-16 20:02:30.049 Status: dzVents: Info: Handling events for: "Woonkamer_Switch", value: "2_hold"
2020-12-16 20:02:30.049 Status: dzVents: Info: Woonkamer_Switch: ------ Start internal script: Script #1: Device: "Woonkamer_Switch (Zigbee2MQTT)", Index: 527
2020-12-16 20:02:30.050 Status: dzVents: Debug: Woonkamer_Switch: Processing device-adapter for Kerstverlichting: Group device adapter
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: Processing device-adapter for Woonkamer_Licht: RGB(W) device adapter
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: Processing device-adapter for Woonkamer_Licht: Switch device adapter
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: OpenURL: url = http://127.0.0.1:9090/json.htm?type=command&param=setcolbrightnessvalue&idx=534&brightness=70&color={"m":3,"t":0,"cw":0,"ww":0,"r":0,"g":255,"b":0}
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: OpenURL: method = GET
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: OpenURL: post data = nil
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: OpenURL: headers = nil
2020-12-16 20:02:30.051 Status: dzVents: Debug: Woonkamer_Switch: OpenURL: callback = nil
2020-12-16 20:02:30.051 Status: dzVents: Info: Woonkamer_Switch: ------ Finished Script #1
2020-12-16 20:02:30.053 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-12-16 20:02:30.066 Status: setcolbrightnessvalue: ID: 216, bri: 70, color: '{m: 3, RGB: 00ff00, CWWW: 0000, CT: 0}
The controlled device "dz.devices('Woonkamer_Licht')" is a zigbee2mqtt group which is converted by the domoticz-zigbee2mqtt-plugin to a domoticz RGBWW dimmer device. The last row of the log is the command send by the device:

Code: Select all

2020-12-16 20:02:30.066 Status: setcolbrightnessvalue: ID: 216, bri: 70, color: '{m: 3, RGB: 00ff00, CWWW: 0000, CT: 0}
So this is the Color control example. What about the WW (color temperature)
When I manually change the WW color temperature of the "dz.devices('Woonkamer_Licht')" to the value I want, the log show this:

Code: Select all

2020-12-16 19:49:52.450 Status: setcolbrightnessvalue: ID: 216, bri: 61, color: '{m: 2, RGB: 000000, CWWW: 59a6, CT: 166}'
How can I control the Color_temp of the WW? m:2 is the color temp attribute?
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

I already figured it out myself...half...
Just added the extra attributes
color temp change is working.....only dimlevel is not working

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('Kerstverlichting')
        local device_2 = dz.devices('Woonkamer_Licht')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },

            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'Off' },
            
            -- setColor(r, g, b, br, cw, ww, m, t, dimlevel)
            ['2_hold'] = {device_2, 'setColor', 0, { 0, 0, 0, 50, 119, 225, 2, 225, 10 } },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

Ah stupid.....the 'br' attribute is the brightness....so dimto() is not needed if 'br' is set
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by waaren »

gschmidt wrote: Wednesday 16 December 2020 20:19 How can I control the Color_temp of the WW? m:2 is the color temp attribute?
m is the colormode. Here set to 2 ; see the

the method setColor accepts more parms (see the API wiki and the dzVents wiki

If I understand you correctly you could try with

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('Kerstverlichting')
        local device_2 = dz.devices('Woonkamer_Licht')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },

            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'Off' },
                                                   -- R,  G,  B, dimlevel, cw, ww,  m, t        (dimlevel, cw, ww, m and t are optional)
            ['2_hold'] = {device_2, 'setColor', 0,   { 0, 255, 0, 70,      89, 166, 2, 166  } },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

waaren wrote: Wednesday 16 December 2020 21:07
gschmidt wrote: Wednesday 16 December 2020 20:19 How can I control the Color_temp of the WW? m:2 is the color temp attribute?
m is the colormode. Here set to 2 ; see the

the method setColor accepts more parms (see the API wiki and the dzVents wiki

If I understand you correctly you could try with

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- change to name of your selector

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('Kerstverlichting')
        local device_2 = dz.devices('Woonkamer_Licht')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },

            ['2_single'] = { device_2, 'On'  },
            ['2_double'] = { device_2, 'Off' },
                                                   -- R,  G,  B, dimlevel, cw, ww,  m, t        (dimlevel, cw, ww, m and t are optional)
            ['2_hold'] = {device_2, 'setColor', 0,   { 0, 255, 0, 70,      89, 166, 2, 166  } },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}

I already figured it out myself....like this: (br = dimLevel)

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- Script for wall switch to control RGBWW devices

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line

        local group_1 = dz.groups('Kerstverlichting')
        local device_2 = dz.devices('Woonkamer_Licht')

        local Z =
        {-- levelname    targetDevice, action, delay, value   -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = {group_1, 'Off', 30 },

            -- setColor attributes (r, g, b, br, cw, ww, m, t)
            ['2_single'] = {device_2, 'setColor', 0, { 0, 0, 0, 70, 119, 180, 2, 180 } },
            ['2_double'] = { device_2, 'Off' },
            ['2_hold'] = {device_2, 'setColor', 0, { 0, 0, 0, 2, 119, 180, 2, 180 } },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by gschmidt »

Hi,

I am using this dzVents Wall Switch script for a while now.

Code: Select all

local ZSelector = 'Woonkamer_Switch' -- Script for wall switch to control RGBWW devices

return
{
    on =
    {
        devices =
        {
            ZSelector,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all OK
        marker = ZSelector,
    },

    execute = function(dz, item)

        -- enter your devices and controls below this line
        local group_1 = dz.groups('Woonkamer Lampen')
        local device_1 = dz.devices('Woonkamer_Licht')
        local device_2 = dz.devices('Tafel_Lamp')

        local Z =
        {   
            -- levelname    targetDevice, action, delay, value -- delay and value are optional
            ['1_single'] = { group_1, 'On'  },
            ['1_double'] = { group_1, 'Off' },
            ['1_hold'] = { device_1, 'setColor', 0, { 0, 0, 0, 30, 0, 180, 2, 180 } },

            -- setColor attributes (r, g, b, br, cw, ww, m, t) -- m:3 is RGB & m:2 WW mode
            ['2_single'] = { device_2, 'dimTo', 0, 15 },
            ['2_double'] = { device_2, 'Off' },
            ['2_hold'] = { device_2, 'dimTo', 0, 70 },
        }

        -- No changes required below this line
        local function switch(object, action, delay, value)
            object.cancelQueuedCommands()
            if action == 'Off' then object.switchOff().afterSec(delay)
            elseif action == 'On' then object.switchOn().afterSec(delay)
            elseif action == 'dimTo' and object.isDevice then object.dimTo(value).afterSec(delay) -- dimTo not available to groups
            elseif action == 'setColor' and object.isDevice then object.setColor(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8]).afterSec(delay)
            else
                dz.log('unknown action (' .. action ..') for object ' .. object.name .. ' ( a ' .. object.baseType ..'). Please report.', dz.LOG_ERROR)
            end
        end

        local row = Z[item.levelName]
        switch(row[1], row[2], ( row[3] or 0 ),  row[4] ) -- object (device / group), action, delay, value 

    end
}
But I was wondering if it is possible to turn off this group:

Code: Select all

 ['1_double'] = { group_1, 'Off' },
and at the same time silently dimTo(80) device_1?

device_1 is a dimmer switch (dimming a group of zigbee bulbs) which, is part of group_1
I also voice control this dimmer switch but it remembers the last dimming level when turned on with Google Home voice.
Now if the Wall_Switch turns off group_1, after ['1_hold'] was selected (which dimTo(30) device_1), Google Home remembers the last dimming level 30. Therefor I want to Turn Off group_1 and silently dimTo(80) device_1
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to control with a Selector Switch (zigbee device)

Post by waaren »

gschmidt wrote: Monday 29 March 2021 20:50 But I was wondering if it is possible to turn off this group:

Code: Select all

 ['1_double'] = { group_1, 'Off' },
and at the same time silently dimTo(80) device_1?
The dimTo(80) will switch device-1 to On with dimlevel 80. The option silent will only prevent any subsequent script from being triggered.
Would it be possible to change the google Home command from switchOn() to dimTo(30) ?
The dimTo(30) is also an implicit switchOn()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to control with a Selector Switch (zigbee device)  [Solved]

Post by gschmidt »

waaren wrote: Monday 29 March 2021 21:25
gschmidt wrote: Monday 29 March 2021 20:50 But I was wondering if it is possible to turn off this group:

Code: Select all

 ['1_double'] = { group_1, 'Off' },
and at the same time silently dimTo(80) device_1?
The dimTo(80) will switch device-1 to On with dimlevel 80. The option silent will only prevent any subsequent script from being triggered.
Would it be possible to change the google Home command from switchOn() to dimTo(30) ?
The dimTo(30) is also an implicit switchOn()
Okay I get it.
I can add group_1 (which dims device_1 to 80) also to Google Home (wih Controlicz), so that would be my second option.
The only thing I need to do is rename the Room name in Google or the dz Group Name (they are now equal: "Woonkamer"), which confuses google.
I was trying avoid that but now I have to.

thanx!

[update] already working
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest