Page 1 of 1

If group is On-Off set Switch On-Off

Posted: Sunday 13 January 2019 12:01
by gschmidt
Hi,

I have created a Virtual Dummy On/Off Switch to set, with a blockly script, a Group (of 4 switches) On-Off for voice control in Google Home.
I used a Virtual Dummy Switch because the wife keeps saying ON-OFF instead of activate/deactivate (Which is for Groups and Scenes)....arrrghhh!
However I also have a KAKU remote which also controls the Switches.

Now the Following Happens:

Turning the Virtual Dummy Switch On/Off With Voice Control and Domoticz buttons is working nicely.
When I turn off/on the 4 Switches with the remote, only the Group and the corresponding Switches nicely are switched On/Off
But the Virtual Switch does not respond offcourse!

How can I set the Virtual Switch to On/Off when the lights are switched on/off by the remote with a Script (Blockly or dzVents)?

Greetzzz,

Gerben

Re: If group is On-Off set Switch On-Off

Posted: Sunday 13 January 2019 12:15
by waaren
gschmidt wrote: Sunday 13 January 2019 12:01 How can I set the Virtual Switch to On/Off when the lights are switched on/off by the remote with a Script (Blockly or dzVents)?
Gerben
If I understand you correctly, you could use the learn mode in the switch tab to create a new switch that will be triggered by your remote and use that switch also in your Blockly.

Re: If group is On-Off set Switch On-Off

Posted: Sunday 13 January 2019 18:34
by gschmidt
I have 4 lights programmed to the remote: 3 buttons to 3 kaku (433) devices, which transmit to the 3 kaku receivers and one button to a learned on/off switch which turns on/off my virtual dimmer switch Yeelight LED RGBWW with a blockly script.So I don't have any buttons left on the remote....

Instead I have put all 4 lights into a group which is triggered by a virtual switch with a blockly script.

I want to tell this virtual switch that if the 4 lights are turned off with the remote (instead of voice or domoticz because this is already working), this virtual switch has to switch to off, beacause all the 4 lights are off...

Is that possible with a dzVents or Blockly script?

Re: If group is On-Off set Switch On-Off  [Solved]

Posted: Sunday 13 January 2019 19:35
by waaren
gschmidt wrote: Sunday 13 January 2019 18:34 Is that possible with a dzVents or Blockly script?
Like this ?

Code: Select all

local lights = {"switch1","switch2","switch3","switch4"}

return {
   on = { devices = lights},     -- Triggers on any of the above switches
   
   execute = function(dz)
      local atLeastOneLightOn 
      local groupSwitch = dz.devices("groupSwitch")
      
      for index,lightName in ipairs(lights) do
        if dz.devices(lightName).state == "On" then atLeastOneLightOn = true end   
      end
      if atLeastOneLightOn then 
            groupSwitch.switchOn().checkFirst().silent()      
      else
            groupSwitch.switchOff().checkFirst().silent()     -- If all switches are Off 
      end
   end
}

Re: If group is On-Off set Switch On-Off

Posted: Monday 14 January 2019 23:35
by gschmidt
Correctomundo...Working

Thanx man!