Page 1 of 1

Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Thursday 27 September 2018 23:06
by misko903
Hi there,
I am trying to program my Xiaomi button switch to toggle yeelight.
When the light is off and I press 1xclick, the light will be switched on
When the light is on and I press 1x click, it will be off

Blockly or whatever, but this is crucial functionality, because of my wife...

Thanks guys!

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Thursday 27 September 2018 23:50
by waaren
misko903 wrote: Thursday 27 September 2018 23:06 I am trying to program my Xiaomi button switch to toggle yeelight.
When the light is off and I press 1xclick, the light will be switched on
When the light is on and I press 1x click, it will be off
Blockly or whatever, but this is crucial functionality, because of my wife...
In dzVents:

Code: Select all

return {

   on = { devices = { "XButton" }},        -- Name of your button
               
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices("Yeelight").toggleSwitch()    -- Name of your Yeelight
        end
   end
}

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Thursday 27 September 2018 23:55
by oldfantome
For Xiaomi button, in parametre ''action on'' put this commande:
http://127.0.0.1:8080/json.htm?type=com ... cmd=Toggle
For ''idx'' put your number of idx your yeelight. (Exemple for me :170)

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Friday 28 September 2018 17:50
by misko903
waaren wrote: Thursday 27 September 2018 23:50
misko903 wrote: Thursday 27 September 2018 23:06 I am trying to program my Xiaomi button switch to toggle yeelight.
When the light is off and I press 1xclick, the light will be switched on
When the light is on and I press 1x click, it will be off
Blockly or whatever, but this is crucial functionality, because of my wife...
In dzVents:

Code: Select all

return {

   on = { devices = { "XButton" }},        -- Name of your button
               
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices("Yeelight").toggleSwitch()    -- Name of your Yeelight
        end
   end
}
Great, it works!!! Thank you
I have changed the names to the IDX, as I will rename the devices later.
i am trying to integrate the Double Click to it too. How does it looks like then?

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Friday 28 September 2018 18:33
by waaren
misko903 wrote: Thursday 27 September 2018 23:06 ... I am trying to program my Xiaomi button switch to toggle yeelight.
... i am trying to integrate the Double Click to it too. How does it looks like then?
something like

Code: Select all

return {

   on = { devices = { 123 }},        -- idx of your button
               
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices(456).toggleSwitch()    -- idx of your Yeelight
        elseif item.state == "Double Click" then
            dz.devices(789).toggleSwitch()    -- idx of your other light
        elseif item.state == "Long Click" then
            -- Just as an example; this will dump all attributes and dzVents functions for this device to the domoticz log
            dz.devices(456).dump()          -- idx of your Yeelight
        else 
            dz.log("state of " .. item.name .. " is now Off")
        end
   end
}

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Friday 28 September 2018 23:50
by misko903
waaren wrote: Friday 28 September 2018 18:33
misko903 wrote: Thursday 27 September 2018 23:06 ... I am trying to program my Xiaomi button switch to toggle yeelight.
... i am trying to integrate the Double Click to it too. How does it looks like then?
something like

Code: Select all

return {

   on = { devices = { 123 }},        -- idx of your button
               
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices(456).toggleSwitch()    -- idx of your Yeelight
        elseif item.state == "Double Click" then
            dz.devices(789).toggleSwitch()    -- idx of your other light
        elseif item.state == "Long Click" then
            -- Just as an example; this will dump all attributes and dzVents functions for this device to the domoticz log
            dz.devices(456).dump()          -- idx of your Yeelight
        else 
            dz.log("state of " .. item.name .. " is now Off")
        end
   end
}
works again :O i rewrited it a bit, controlling now 2 lamps and one plug. works like a charm!
many thanks :)

PS: inbetween, the Mijia Bluetooth TH sensor works too :)

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Thursday 04 October 2018 15:07
by madvisionz
The script works for one device/light, but how can I add/control more lights in a state?
For example. I have a switch with two buttons, click 1 and click 2. Now I want to turn on/off two lights/devices (456 and 789) the same time when state is "Click 1" and turn on/off three lights at the same time (123,268 and 369) when state is "Click 2".

Should this work?

return {

on = { devices = { 123 }}, -- idx of your button

execute = function(dz, item )
if item.state == "Click" then
dz.devices(456).toggleSwitch() -- idx of Yeelight 1
dz.devices(789).toggleSwitch() -- idx of Yeelight 2
elseif item.state == "Click 2" then
dz.devices(123).toggleSwitch() -- idx of Yeelight 3
dz.devices(268).toggleSwitch() -- idx of Yeelight 4
dz.devices(369).toggleSwitch() -- idx of Yeelight 5
end
end
}

Or should I work with device groups then maybe?

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Monday 08 October 2018 7:04
by misko903
IMHO, the lights can have different state - two are on, one is off. if you will toggle, then two bill be off, one on. I suppose it needs to be grouped. At least, it was in Xiaomi MiHome like this, and I think the logic will remain.

BTW, you can use all 3 yeelights in one line like this:

Code: Select all

dz.devices(123, 268, 369).toggleSwitch() -- idx of Yeelight 3, 4 and 5

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Monday 08 October 2018 18:29
by paulie72
I have the same issue can this be done in Blocky because i do not have script skills?

Sent from my COL-L29 using Tapatalk


Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Tuesday 16 October 2018 7:00
by misko903
No idea, i did not find toggleSwitch() function in Blockly. That is why I have chosen dzVents...

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Tuesday 16 October 2018 12:25
by dandanger
You could just check the state of light like this: click -> if light is off = turn on. click -> if light is on = turn off.

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Wednesday 17 October 2018 9:21
by misko903
dandanger wrote: Tuesday 16 October 2018 12:25 You could just check the state of light like this: click -> if light is off = turn on. click -> if light is on = turn off.
i was trying to do it this way, with blockly. it was not working.

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Wednesday 17 October 2018 10:51
by dandanger
misko903 wrote: Wednesday 17 October 2018 9:21
dandanger wrote: Tuesday 16 October 2018 12:25 You could just check the state of light like this: click -> if light is off = turn on. click -> if light is on = turn off.
i was trying to do it this way, with blockly. it was not working.
Maybe you could attach picture from your test blockly? And you had "else if" used?

Re: Toggle button switch: 1x Click ON, 1xClick OFF

Posted: Wednesday 17 October 2018 11:59
by misko903
I think it was like this
Image