Switch a Mixed Group to on with toggle command  [Solved]

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

Moderator: leecollings

Post Reply
Harald777
Posts: 50
Joined: Thursday 01 June 2017 8:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Switch a Mixed Group to on with toggle command

Post by Harald777 »

Hi there,

I am totally new with DzVents scripting so looking for a solution / tip for the following issue:

I have a Aqara dual rocker wall switch, named "Gang schakelaar' and I want to control the following lights / group with the the Aquara outputs B1, B2, B3 & B6.:

- Group "Woonkamer" (with 5 lights) toggle on B1 input - (single push lh switch)
- Light "Eettafel" toggle on B2 input - (single push rh switch)
- Light "Vloerlamp" toggle on B6 input - (dual push rh switch)
- Light ''Tuinverlichting" toggle on B3 input - (dual push lh switch)

Used the following code:

Code: Select all

return {

   on = { devices = { "Gang schakelaar" }           },
      
   execute = function(dz, switch )
      
      if switch.state == "B2" then
            dz.devices("Eettafellamp").toggleSwitch()
      elseif switch.state == "B6" then
            dz.devices("Vloerlamp").toggleSwitch()
      elseif switch.state == "B3" then
            dz.devices("Tuinverlichting").toggleSwitch()
      elseif switch.state == "B1" then
            dz.groups("Woonkamer").toggleGroup()        
      end
   end
}
All is working fine as long as the group "Woonkamer" is in the state On or OFF.
As soon as this group in in the state "Mixed" the toggelGroup command is not working.

Is there a way to switch my "Woonkamer" group to on when it is in a mixed state?
Perhaps my approach on this is totally wrong, please let my know, any tips are much appreciated.

Greetings, Harald
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch a Mixed Group to on with toggle command

Post by waaren »

Harald777 wrote: Wednesday 11 December 2019 20:52 Is there a way to switch my "Woonkamer" group to on when it is in a mixed state?
Yes; method to use is
switchOn()

Code: Select all

return 
{
    on = 
    {
        devices = { 'Gang schakelaar' },
    },

    logging = { level = domoticz.LOG_DEBUG }, -- switch to LOG_ERROR when working as expected

    execute = function(dz, item)
	    _G.logMarker =  _G.moduleLabel
      
        local Eettafellamp = dz.devices("Eettafellamp")
        local VloerLamp = dz.devices("Vloerlamp")
        local TuinVerlichting = dz.devices("Tuinverlichting")
        local Woonkamer = dz.groups("Woonkamer")
      
        if item.state == "B2" then
            Eettafellamp.toggleSwitch()
        elseif item.state == "B6" then
            Vloerlamp.toggleSwitch()
        elseif item.state == "B3" then
            Tuinverlichting.toggleSwitch()
        elseif item.state == "B1" then
            if Woonkamer.state ~= 'Mixed'then 
                Woonkamer.toggleGroup()        
            else
                Woonkamer.switchOn()
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Harald777
Posts: 50
Joined: Thursday 01 June 2017 8:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Re: Switch a Mixed Group to on with toggle command  [Solved]

Post by Harald777 »

waaren wrote: Wednesday 11 December 2019 21:38 Yes; method to use is switchOn()
Waaren, thanks again for you assistance, working realy great now.

I have a lot to learn about Lua and DzVentz scripting.
Using Domoticz for a couple of years and until know only used Blockly for scenarios.
But the possibilities with scripts are much more extensive but also more complicated and I have to spent a lot more time in learning the scripts basic.

For know this is working great, thanks.

Greetings, Harald
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest