Toggle button switch: 1x Click ON, 1xClick OFF Topic is solved

Moderator: leecollings

Post Reply
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
oldfantome
Posts: 12
Joined: Wednesday 19 September 2018 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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)
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post 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 :)
madvisionz
Posts: 12
Joined: Tuesday 25 September 2018 12:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10327
Contact:

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

Post 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?
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post 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
paulie72
Posts: 5
Joined: Monday 08 October 2018 11:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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

misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post by misko903 »

No idea, i did not find toggleSwitch() function in Blockly. That is why I have chosen dzVents...
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post 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.
dandanger
Posts: 9
Joined: Thursday 23 August 2018 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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?
misko903
Posts: 51
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

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

Post by misko903 »

I think it was like this
Image
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest