Page 1 of 1

Switch a Mixed Group to on with toggle command

Posted: Wednesday 11 December 2019 20:52
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

Re: Switch a Mixed Group to on with toggle command

Posted: Wednesday 11 December 2019 21:38
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
}

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

Posted: Thursday 12 December 2019 9:15
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