HowTo: Controlling hue scenes through OH

At the beginning of using OH I was using lots of hue bulbs and created lots of scenes with the hue bridge. I was looking for a solution controlling the hue scenes in OH inside rules without defining every bulb’s color, brightness etc.
The solution I found is actually quite simple and I would say it’s more like a workaround for controlling the hue scenes.
But I think it is quite usefull having an easy way especially for new OH users.

First off all you need to install node-red. If you`re using the very comfortable Openhabian, just go to the console and install it through the Openhabian Config Menu.

1. Step
Create an scene-item for example:

String    hue_scenes              "Szenen hue"            <light>

2.Step
Open node-red and through http://openhabianpi:1880 and install the addon huemagic. It’s a very nice Addon for node-red and works like a charm. Many thanks to Foddy for that. :hugs: Find more Information
Menu->Manage Palette->Install-> Search for huemagic
3.Step
Now we need some nodes for controlling the scenes:
Put in the following nodes:


Configure them as following:

For the details you can easily just import the folowing nodes:

[{"id":"5b2b2114.28912","type":"openhab2-in","z":"4968106a.aefd4","name":"","controller":"aef807de.f24a58","itemname":"hue_scenes","x":143,"y":106,"wires":[["2310c3ff.df823c"],[]]},{"id":"6b277c5e.0dad74","type":"function","z":"4968106a.aefd4","name":"Szene EIN","func":"msg.payload={\"on\":true};\nreturn msg;","outputs":1,"noerr":0,"x":495,"y":84,"wires":[["87fd07d.5a694f8"]]},{"id":"87fd07d.5a694f8","type":"hue-scene","z":"4968106a.aefd4","name":"Wz warm gedimmt","bridge":"45f0a0be.46688","sceneid":"OxpNyXa2eRJ43Tc","x":669,"y":84,"wires":[[]]},{"id":"7b9ff31a.eb105c","type":"hue-group","z":"4968106a.aefd4","name":"Wohnzimmer","bridge":"45f0a0be.46688","groupid":"1","colornamer":true,"x":649,"y":132,"wires":[[]]},{"id":"e3c0e73a.514358","type":"function","z":"4968106a.aefd4","name":"Szene AUS","func":"msg.payload={\"on\":false};\nreturn msg;","outputs":1,"noerr":0,"x":495,"y":132,"wires":[["7b9ff31a.eb105c"]]},{"id":"2310c3ff.df823c","type":"switch","z":"4968106a.aefd4","name":"Weiche","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"WZ warm gedimmt","vt":"str"},{"t":"eq","v":"aus","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":306,"y":107,"wires":[["6b277c5e.0dad74"],["e3c0e73a.514358"]]},{"id":"aef807de.f24a58","type":"openhab2-controller","z":"","name":"Openhab","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""},{"id":"45f0a0be.46688","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.XXX.XXX","key":"XXXXXXXXXXXXXXXXXXXXXX","interval":"3000"}]

As you can see, my scene is called “WZ war gedimmt”, but that depends on your found scenes through the scene-node.
4.Step
Control the scenes through a rule in OH:

rule "Scene ON"
when
	Item KeyFob changed
then
	switch (KeyFob.state) 
	{
        case 1.0:
            hue_scenes.sendCommand("WZ warm gedimmt")
	    case 2.0: 
            hue_scenes.sendCommand("aus")			
	}
end

That’s it. Quite easy isn’t it?

4 Likes

@oeo Followed your guide, can dont seem to have the hue bulb changing run some debugging stuff on node-red and not getting any response.

So you cannot control the scenes? Do you see the scenes in your huemagic nodes? Are the plugins openhab and huemagic installed? If possible post the nodes as export out of nodered.

Yup, Hue Binding is installed and i can turn the light on and off and use the color wheel to change the colours, basically copied your exported project and just changed the Scene and the Room Group but when using the debug i can see the switch receving the ON / OFF Statements but nothing changes.

These are the current binding i have installed:

Version of NodeRED MagicHue Installed
image

This is what i was messing around with last night to try and see if i could find the issue:

The hueswitch node state is off, but the hue color lamp is"turned on 100%". So there is something wrong in your switch and I think you need a function node to send off as payload.

Sure so if i was to start over how would you suggest?

Please put an function node before the hue lamp node. Then write in the content from my function node “Szene aus”. If its not working please export your flow to clipboard and insert the stuff here.

Ok so ive done this:

Which when i deploy has turned the light off but i didnt toggle the switch

Here is my current flow

[{“id”:“a2c1e463.468558”,“type”:“tab”,“label”:“Flow 2”,“disabled”:false,“info”:""},{“id”:“e529214d.7e2798”,“type”:“openhab2-in”,“z”:“a2c1e463.468558”,“name”:"",“controller”:“5af1190a.a11598”,“itemname”:“HueSwitch”,“x”:129,“y”:154,“wires”:[[“557e129f.726eac”],[]]},{“id”:“557e129f.726eac”,“type”:“switch”,“z”:“a2c1e463.468558”,“name”:"",“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“ON”,“vt”:“str”},{“t”:“eq”,“v”:“OFF”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:308,“y”:156,“wires”:[[“168dd0f3.d8b6ff”],[“168dd0f3.d8b6ff”]]},{“id”:“168dd0f3.d8b6ff”,“type”:“function”,“z”:“a2c1e463.468558”,“name”:“Szene AUS”,“func”:“msg.payload={“on”:false};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:493,“y”:155,“wires”:[[“926393d0.e772e”,“f83c8cce.a071b8”]]},{“id”:“926393d0.e772e”,“type”:“hue-light”,“z”:“a2c1e463.468558”,“name”:“Hue color lamp 1”,“bridge”:“fa31eb1d.e5da38”,“lightid”:“3”,“colornamer”:true,“x”:768.7666015625,“y”:159.48330688476562,“wires”:[[]]},{“id”:“f83c8cce.a071b8”,“type”:“debug”,“z”:“a2c1e463.468558”,“name”:“hue_bulb_report”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload”,“x”:777,“y”:58,“wires”:[]},{“id”:“5af1190a.a11598”,“type”:“openhab2-controller”,“z”:"",“name”:“hme-openhab”,“protocol”:“http”,“host”:“localhost”,“port”:“8080”,“path”:"",“username”:"",“password”:""},{“id”:“fa31eb1d.e5da38”,“type”:“hue-bridge”,“z”:"",“name”:“HueBridge”,“bridge”:“172.16.40.xx”,“key”:“xxxx”,“interval”:“3000”}]

@oeo been playing with this for the last 10 minutes and got the bulb to now turn on and off

Got the scenes working doing this;

[{“id”:“1c80a180.540b6f”,“type”:“hue-scene”,“z”:“e67208d5.1ea8e8”,“name”:“Spring Blossom”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“hRJqK719Xd1GwHE”,“x”:957,“y”:4463,“wires”:[[“374d9f36.09a0b8”]]},{“id”:“fa31eb1d.e5da38”,“type”:“hue-bridge”,“z”:"",“name”:“HueBridge”,“bridge”:“0.0.0.0”,“key”:"",“interval”:“3000”}]

Yes thats it. Now you can control the hue scenes, saved on the hue bridge.

Ben do you know if we can extract all available scenes automatically somehow so we don’t have to hardcode? I would like to assign the scenes to a Selection on my Sitemap.
Other than that thanks for the info the provided example works as described.

The problem is, that the scenes are not available in OH. Thats why I used this way through nodered. Should be possible writing the scenes in a field, but as far as I know theres no easy way to read this field in OH.

I thought maybe through NodeRed as well. Just provide it somehow to OpenHab from NodeRed. NodeRed at least can load the scene list, but I can’t find a way to transfer this list to OpenHab

Hi Smooney!

Is it possible to post the whole config for this scenes?

I mean the whole export of the node-red konfig, and also the things, items, sitemap stuff from openhab to understand how this all is working together?

I will adapt this to my needs…

Thank you and BR
Alex

Hey Alex,

Sure when i get home tonight i’ll upload everything for you :slight_smile:

Great! Thank you very much! This will help me allot!

Hey Alex,

NodeRED Code
[{“id”:“6aef4c83.a23284”,“type”:“tab”,“label”:“Second Floor Bedroom”,“disabled”:false,“info”:""},{“id”:“1fa55790.d7a2e8”,“type”:“openhab2-in”,“z”:“6aef4c83.a23284”,“name”:"",“controller”:“5af1190a.a11598”,“itemname”:“sfbedroom_hue_selector”,“x”:132,“y”:253,“wires”:[[“8c7c7e9e.5ad37”],[]]},{“id”:“8c7c7e9e.5ad37”,“type”:“switch”,“z”:“6aef4c83.a23284”,“name”:“hue_profiles”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“scene_1”,“vt”:“str”},{“t”:“eq”,“v”:“scene_2”,“vt”:“str”},{“t”:“eq”,“v”:“scene_3”,“vt”:“str”},{“t”:“eq”,“v”:“scene_4”,“vt”:“str”},{“t”:“eq”,“v”:“scene_5”,“vt”:“str”},{“t”:“eq”,“v”:“scene_6”,“vt”:“str”},{“t”:“eq”,“v”:“scene_7”,“vt”:“str”},{“t”:“eq”,“v”:“scene_8”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:8,“x”:350.5,“y”:252,“wires”:[[“471f2448.cef51c”],[“c3517138.b67728”],[“9b94a1ed.5c7d8”],[“a7e77d2f.14ac88”],[“5fd343bb.763554”],[“cc86e62.bdecf98”],[“9cb7c66e.3f78”],[“e1f53d13.69034”]]},{“id”:“471f2448.cef51c”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:649,“y”:60,“wires”:[[“e64df23a.1b89c”]]},{“id”:“e64df23a.1b89c”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Concentrate”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“8p5Qx7o2quiSMO-”,“x”:918,“y”:72,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“c3517138.b67728”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:648,“y”:94,“wires”:[[“3cf33f0e.fe5118”]]},{“id”:“3cf33f0e.fe5118”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Reading”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“3dt9QxN2ZYuHjig”,“x”:909,“y”:109,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“5fd343bb.763554”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:653,“y”:203,“wires”:[[“76bddf3.1860da”]]},{“id”:“9b94a1ed.5c7d8”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:646,“y”:129,“wires”:[[“67b79d9a.d39c5c”]]},{“id”:“67b79d9a.d39c5c”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Relax”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“yaX6oWwZ1B0hmzB”,“x”:898,“y”:143,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“76bddf3.1860da”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Savanna Sunset”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“1jVFGTvMbfe-kVZ”,“x”:945,“y”:216,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“cf2eeea2.8b7428”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Tropical Twilight”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“ZM31ewb5ciSbOJJ”,“x”:935,“y”:251,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“c4de8746.1c152”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Arctic Aurora”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“AzSkcyG6LLEALvh”,“x”:924,“y”:285,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“ad7e7977.a0dec8”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Spring Blossom”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“hRJqK719Xd1GwHE”,“x”:934,“y”:322,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“cc86e62.bdecf98”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:651,“y”:240,“wires”:[[“cf2eeea2.8b7428”]]},{“id”:“9cb7c66e.3f78”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:650,“y”:274,“wires”:[[“c4de8746.1c152”]]},{“id”:“e1f53d13.69034”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:648,“y”:309,“wires”:[[“ad7e7977.a0dec8”]]},{“id”:“f0ecd66.d5801a8”,“type”:“hue-group”,“z”:“6aef4c83.a23284”,“name”:“Second Floor Bedroom”,“bridge”:“fa31eb1d.e5da38”,“groupid”:“2”,“colornamer”:true,“x”:1235,“y”:240,“wires”:[[]]},{“id”:“a7e77d2f.14ac88”,“type”:“function”,“z”:“6aef4c83.a23284”,“name”:“msg.payload={“on”:true};”,“func”:“msg.payload={“on”:true};\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:644,“y”:164,“wires”:[[“c659321d.791998”]]},{“id”:“c659321d.791998”,“type”:“hue-scene”,“z”:“6aef4c83.a23284”,“name”:“Dimmed”,“bridge”:“fa31eb1d.e5da38”,“sceneid”:“LneJdBNW0irn3Ha”,“x”:906,“y”:178,“wires”:[[“f0ecd66.d5801a8”]]},{“id”:“5af1190a.a11598”,“type”:“openhab2-controller”,“z”:"",“name”:“hme-openhab”,“protocol”:“http”,“host”:“localhost”,“port”:“8080”,“path”:"",“username”:"",“password”:""},{“id”:“fa31eb1d.e5da38”,“type”:“hue-bridge”,“z”:"",“name”:“HueBridge”,“bridge”:“172.16.40.51”,“key”:“J2NwEdTy93I4knRrwrEVWr1D4MNamPj7RcRMob7N”,“interval”:“3000”}]

SITEMAP
Colorpicker item=sfbedroom_huecolour1_Colour
Selection item=sfbedroom_hue_selector mappings=[scene_1=“Concentrate”, scene_2=“Reading”, scene_3=“Relaxed”, scene_4=“Dimmed”,scene_5=“Savanna Sunset”, scene_6=“Tropical Twilight”, scene_7=“Arctic Aurora”, scene_8=“Spring Blossom”] icon=“custom_colourwheel”
Slider item=sfbedroom_huecolour1_Dimmer

Thats all i have, but then you need the Hue Binding and NodeRed Binding

Thank you very much!
I will try it tomorrow if I get it to work!

1 Like

Is you don’t drop me a pm and we can sort it!