mattmattmatt / node-red-contrib-yeelight-compat-hue

💡 A Node-RED node for controlling Yeelight devices, compatible with node-red-contrib-node-hue flows.
https://flows.nodered.org/node/node-red-contrib-yeelight-compat-hue
MIT License
10 stars 12 forks source link

State Toggle functionality #9

Open Orgjvr opened 6 years ago

Orgjvr commented 6 years ago

Is there a way to implement a Toggle functionality?

What I mean is if the light is ON, then switch it OFF or if it is OFF then switch it ON.

I tried to implement it by first querying the state and then to request the opposite state. The problem is, that as soon as the new state is implemented, the node which I used to query the current state, acts on the new state and sends the opposite state. Thus creating an endless loop!

My use case is in fact a physical toggle button which the wife wants to press to toggle the state :)

Thanks for a great node.

soloam commented 5 years ago

I had this exact same problem, what I did was add a flag (trigger = true) before the node that requests the state, after I get a response I check if the trigger is set, when is a automatic trigger that flag is not set, and I ignore the message.

[{"id":"60191714.068958","type":"switch","z":"2077f7db.a8cc48","name":"Node ID","property":"nodeId","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":280,"y":120,"wires":[["9bedbb70.ae26d8"],["840ebdf1.d040a"]]},{"id":"9bedbb70.ae26d8","type":"switch","z":"2077f7db.a8cc48","name":"Child ID","property":"childSensorId","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":80,"wires":[["3874706d.6c1e2"]]},{"id":"840ebdf1.d040a","type":"switch","z":"2077f7db.a8cc48","name":"Child ID","property":"childSensorId","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":160,"wires":[["8107e40.5f5f12"]]},{"id":"8107e40.5f5f12","type":"yeelight-compat-hue-state","z":"2077f7db.a8cc48","name":"","server":"31a4dbf9.3486b4","x":650,"y":160,"wires":[["dddb3fe4.25cdd"]]},{"id":"3874706d.6c1e2","type":"yeelight-compat-hue-state","z":"2077f7db.a8cc48","name":"","server":"75c54093.00cfb","x":650,"y":80,"wires":[["dddb3fe4.25cdd"]]},{"id":"469a7c44.a69ff4","type":"change","z":"2077f7db.a8cc48","name":"inject","rules":[{"t":"set","p":"inject","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":120,"wires":[["60191714.068958"]]},{"id":"dddb3fe4.25cdd","type":"switch","z":"2077f7db.a8cc48","name":"Inject Check","property":"inject","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":120,"wires":[["1696eeff.781261"]]},{"id":"1696eeff.781261","type":"change","z":"2077f7db.a8cc48","name":"Remove Inject","rules":[{"t":"delete","p":"inject","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":120,"wires":[[]]},{"id":"31a4dbf9.3486b4","type":"yeelight-compat-hue-config","z":"","hostname":"192.168.1.11","port":"55443","name":"Y2"},{"id":"75c54093.00cfb","type":"yeelight-compat-hue-config","z":"","hostname":"192.168.1.10","port":"55443","name":"Y1"}]

This node is very useful, but I really miss a option to no auto trigger (or a separated node to incoming messages and requests) a feedback of errors on the nodes (so that I can retry if a timeout occurs) and the toggle option.

jpg06 commented 5 years ago

Hi, I have the same need as you do: a "toggle" command to change the state light. I proposed a code change to resolve this and put the code in the "pull request" section Friendly, Jean-Paul

jpg06 commented 5 years ago

Hi,

it's the first time i really use github for code modify. I think i found how to do a "pull request" and i hope it is in accordance this the way to do if.

Jean-Paul

jpg06 commented 5 years ago

Some extra 'space' will give unsucces travis tool. Now it is Ok. What do you think of my "pull request" proposal ?