Use GPIO for switching Hue lights on

Hey there,
I have a problem with my node red configuration.

I'm looking for a good solution for switching hue lights on via the gpio pins.
When the circuit is closed, Node Red should turn on a Hue lamp for one minute. Then you should go out again.
So far I have solved this via "rpi gpio in". But I'm not getting anywhere now. I use "HueMagic" to control Hue. Unfortunately, I don't find anything useful in the documentation here either.
Does anyone have a specific idea how I could solve this or can someone show me where I can find help for my problem?
That would be awesome. Thank you!

Hi there have you got your Hue-Bridge-Node configured into Node-Red?

Once you've got that cooking it should be fairly straight forward to use a GPI to initiate the Hue output.

Yes, I did this. Could you show me a sample config of this issue?

This is part of my flow


It's controlled from a switch but if you combine it with the buttons I did in this project https://flows.nodered.org/flow/4b3f2cd44ebfa4689ec13c34dc576d56 see how you go.

[{"id":"90060fee.df85e8","type":"hue-light","z":"1178ee8c.0984a9","name":"Living Room","bridge":"8b347d00.5d7e4","lightid":"2","colornamer":true,"skipevents":false,"x":630,"y":140,"wires":[["b0a4e5a0.48cfd"]]},{"id":"9c85eb9.ef02618","type":"ui_slider","z":"1178ee8c.0984a9","name":"","label":"","tooltip":"","group":"98d5dae6.05357","order":3,"width":"5","height":"1","passthru":false,"outs":"all","topic":"","min":0,"max":"100","step":"5","x":270,"y":200,"wires":[["2d9a45ce.2ddaf2","7821abc4.fbe74c"]]},{"id":"2d9a45ce.2ddaf2","type":"function","z":"1178ee8c.0984a9","name":"Brightness","func":"return {payload: { brightness: msg.payload } };","outputs":1,"noerr":0,"x":410,"y":200,"wires":[["90060fee.df85e8"]]},{"id":"fc1f0f74.4c5c28","type":"ui_switch","z":"1178ee8c.0984a9","name":"","label":"","tooltip":"","group":"98d5dae6.05357","order":2,"width":1,"height":1,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":270,"y":140,"wires":[["90060fee.df85e8"]]},{"id":"b0a4e5a0.48cfd","type":"link out","z":"1178ee8c.0984a9","name":"","links":["ba3aec13.334c1"],"x":795,"y":140,"wires":[]},{"id":"87a2aacc.b2f3c8","type":"function","z":"1178ee8c.0984a9","name":"splitter","func":"return [\n    { payload: msg.payload.on },\n    { payload: msg.payload.brightness }\n];","outputs":2,"noerr":0,"x":130,"y":160,"wires":[["fc1f0f74.4c5c28"],["9c85eb9.ef02618"]]},{"id":"ba3aec13.334c1","type":"link in","z":"1178ee8c.0984a9","name":"","links":["b0a4e5a0.48cfd"],"x":35,"y":160,"wires":[["87a2aacc.b2f3c8"]]},{"id":"8f902501.c4af18","type":"comment","z":"1178ee8c.0984a9","name":"Lighting Control","info":"","x":100,"y":100,"wires":[]},{"id":"7821abc4.fbe74c","type":"ui_text","z":"1178ee8c.0984a9","group":"98d5dae6.05357","order":1,"width":0,"height":0,"name":"Level","label":"Living Room","format":"{{msg.payload}}","layout":"row-spread","x":390,"y":160,"wires":[]},{"id":"8b347d00.5d7e4","type":"hue-bridge","z":"","name":"Beaver Hue","bridge":"10.1.1.108","key":"txr199imLMnsQRFZW6t8szTvUFbAh0KxxT1Wn4zV","interval":"2000","disableupdates":false},{"id":"98d5dae6.05357","type":"ui_group","z":"","name":"Living Room","tab":"e403be4.fc56ec","order":1,"disp":false,"width":"6","collapse":false},{"id":"e403be4.fc56ec","type":"ui_tab","z":"","name":"Lighting","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Thanks, that helped a lot.
Now when I close the circuit, the lamp lights up and when I interrupt it, it goes dark.

Is it now possible that closing the circuit always sets the lamp to 70% (a certain brightness) and a specific color? And holds it for a certain period (e.g. for 30 seconds) even after the circuit has been interrupted. After this time the lamp should go out again.

[{"id":"b35b3879.4b35c8","type":"rpi-gpio in","z":"3f36c9a0.6cd7e6","name":"","pin":"7","intype":"down","debounce":"25","read":false,"x":310,"y":240,"wires":[["c907caca.fc2cf8"]]},{"id":"935ab6ee.46fe98","type":"hue-light","z":"3f36c9a0.6cd7e6","name":"Deckenlampe","bridge":"860328d4.677a68","lightid":"3","colornamer":true,"skipevents":false,"x":700,"y":160,"wires":[[]]},{"id":"c907caca.fc2cf8","type":"function","z":"3f36c9a0.6cd7e6","name":"Brightness","func":"return {payload: { brightness: msg.payload } };","outputs":1,"noerr":0,"x":470,"y":220,"wires":[["935ab6ee.46fe98"]]},{"id":"860328d4.677a68","type":"hue-bridge","z":"","name":"Hue Bridge","bridge":"192.168.178.43","key":"VRVGHy5C3Gi-dBuucQAbs0-Q0RCkFEtKedLfpNsl","interval":"3000","disableupdates":false}]

Yeah defo if you look at the flow in the Qlab you can use the top line of the flow for the GPI to strip out the leading edge of the GPI, so when it's pressed do X. and use that to trigger your flow that turns the light on at the colour of your chose. Bang a delay node into trigger the off command when ever you want.

Thx, could you pls sende me the nodes?
Now the colour is right (rgb code) but if the state of the gpi goes down, the light will not

Have a look at this https://flows.nodered.org/flow/4b3f2cd44ebfa4689ec13c34dc576d56

So I understand correctly that I need a change node to evaluate the GPI interface?
And how exactly do I have to give HueMagic the instructions? I really don't understand that yet.
But thank you in advance for your great help!

Maybe simplify it. Grab an inject node, make sure your flow works for there, then introduce the GPI. Or do it the other way get the GPI via your flow return the triggers you need and away you go.

Ok I replaced the gpi node with an inject.
I set a trigger node between the inject and the two functions. but for now the lights remains on after the set time.

yeah you need to have a command to set the light to off something a bit like this

Thx, it works!

https://pastebin.com/NLTP7Erh

1 Like

Excellent

So I'm back: I have now carried out some tests and found another problem.
The GPIO node only passes on the impulse when the current drops again. It would be important, however, that the action runs as soon as the tension is maintained. How can I achieve this?

I'm not sure I'm following what the fault now is. I've just thrown this together and modified your LX on cue as I don't believe you need the quote marks around the array component. Also I removed the rgb as I only have white lights.

[{"id":"9b7e3cf5.c34cc","type":"inject","z":"1178ee8c.0984a9","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":3120,"wires":[["5fc3ab61.d16864"]]},{"id":"5fc3ab61.d16864","type":"switch","z":"1178ee8c.0984a9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":3080,"wires":[["fd8ab316.de9738","e041a561.da445"],]},{"id":"1d02bcac.5b94fb","type":"rpi-gpio in","z":"1178ee8c.0984a9","name":"","pin":"11","intype":"down","debounce":"25","read":false,"x":320,"y":3060,"wires":[["5fc3ab61.d16864"]]},{"id":"67db047a.d0c214","type":"hue-light","z":"1178ee8c.0984a9","name":"Back Room","bridge":"8b347d00.5d7e4","lightid":"1","colornamer":true,"x":930,"y":3080,"wires":[["2fc15651.f4b36a"]]},{"id":"e041a561.da445","type":"delay","z":"1178ee8c.0984a9","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":600,"y":3100,"wires":[["1368a198.9821ee"]]},{"id":"1368a198.9821ee","type":"function","z":"1178ee8c.0984a9","name":"Lampe aus","func":"return {payload: { on: false } };","outputs":1,"noerr":0,"x":750,"y":3100,"wires":[["67db047a.d0c214"]]},{"id":"fd8ab316.de9738","type":"function","z":"1178ee8c.0984a9","name":"Lampe an","func":"msg.payload={\n\ton:true,\n\tbrightness:65,\n}\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":3060,"wires":[["67db047a.d0c214"]]},{"id":"2fc15651.f4b36a","type":"debug","z":"1178ee8c.0984a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1090,"y":3080,"wires":},{"id":"8b347d00.5d7e4","type":"hue-bridge","z":"","name":"Beaver Hue","bridge":"10.1.1.108","key":"txr199imLMnsQRFZW6t8szTvUFbAh0KxxT1Wn4zV","interval":"2000","disableupdates":false}]

Screenshot 2020-05-20 at 21.01.38

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.