Toggle button switch: 1x Click ON, 1xClick OFF Topic is solved
Moderator: leecollings
-
- 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
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!
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!
- 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
In dzVents: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...
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- 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
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)
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)
-
- 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
Great, it works!!! Thank youwaaren wrote: ↑Thursday 27 September 2018 23:50In dzVents: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...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 }
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?
- 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
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- 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
works again :O i rewrited it a bit, controlling now 2 lamps and one plug. works like a charm!waaren wrote: ↑Friday 28 September 2018 18:33something likeCode: 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 }
many thanks

PS: inbetween, the Mijia Bluetooth TH sensor works too

-
- 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
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?
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?
-
- 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
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:
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
-
- 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
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
Sent from my COL-L29 using Tapatalk
-
- 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
No idea, i did not find toggleSwitch() function in Blockly. That is why I have chosen dzVents...
-
- 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
You could just check the state of light like this: click -> if light is off = turn on. click -> if light is on = turn off.
-
- 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
Maybe you could attach picture from your test blockly? And you had "else if" used?
-
- 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
I think it was like this


Who is online
Users browsing this forum: No registered users and 1 guest