Hue Magic - Dashboard slider for brightness ?!

Hi

I’m struggling to make a dashboard slider work as a brightness level controller for a hue light bulb.

I already have an injection node (below) with JavaScript that works to set a specific brightness level , it sends the following message to turn on and set the correct levels - but I can’t seem to convert the logic to work with the level set via a slider.

{"on":true,"brightness":60}

Feeding a slider into a template node, I tried the following, but that did not work.

{"on":true,"brightness":{{msg.payload}}}

By any chance does anyone have a working example of using a slider with a hue magic node?

Many thanks

Join the party... :partying_face:
https://discourse.nodered.org/search?q=hue%20slider

Hi @shrickus

I’m at the party ,with drink in hand :slight_smile: and I did have a look around the forum before going in with my post but I couldn’t find anything specific ?

Am I missing something obvious-? Would you be able to be more specific in what your are suggesting - all help is appreciated.

The template output is a string, so you have to convert the string to an object, add a json node to the template output.

the (not ui) template node can also output JSON directly if you want

[{"id":"f0a3358.40408c8","type":"ui_slider","z":"d511095d.512808","name":"","label":"slider","group":"ccbdd82d.3c19b8","order":0,"width":0,"height":0,"passthru":true,"topic":"","min":0,"max":"100","step":1,"x":155,"y":1125,"wires":[["377828bf.3ea638"]]},{"id":"377828bf.3ea638","type":"template","z":"d511095d.512808","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"on\":true,\"brightness\":{{payload}} }","output":"json","x":315,"y":1125,"wires":[["4175b7ca.1aa658"]]},{"id":"4175b7ca.1aa658","type":"debug","z":"d511095d.512808","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":520,"y":1125,"wires":[]},{"id":"ccbdd82d.3c19b8","type":"ui_group","z":"","name":"Default","tab":"7d974e73.cf8f9","order":3,"disp":true,"width":"6","collapse":false},{"id":"7d974e73.cf8f9","type":"ui_tab","z":"d511095d.512808","name":"Home","icon":"link","order":1}]

Right, I missed the setting output as at the bottom.

BTW a similar setting for the mqtt-in node would be helpful.

YES PLEASE!

Somewhat offtopic

Almost all my mqtt-in nodes receive JSON strings that I've to convert to objects.

what has this to do with Hue and Dashboard sliders ?
Please start another thread for another topic.

Sorry, I thought offtopic relating to mqtt. Never mind.

Thanks for that, I’ve converted the template to output as a JSON, but the slider values I choose do not pass through ?

Here is the code in the template, which is fed from the slider..

{"on":true,"brightness":{{msg.payload}}}

Here is the debug output ?

06/10/2018, 19:58:08.  node: 1a4e98fb.364c9f
msg.payload : Object
object
data: object
on: true
brightness: ""

Any ideas ?

There's a (confusing) little hint, hidden in the default template:
image

Notice that the mustache syntax is expanding payload, not msg.payload. That's because the core template's mustache syntax evaluator works on the complete msg object, allowing you access to other msg properties like msg.topic or msg.parts.

Bottom line: in this case, it should work if you drop the "msg." prefix. Most other places you will need to use the "msg." prefix, except in a JSONata expression, where it's use is optional (and deprecated!)... and now you know why I'm drinking while typing this.

1 Like

Many thanks for that nugget @shrickus :grin:

I’ve made the change and the object being sent looks to work now...

{"on":true,"brightness":{{payload}}}

Here is the debug output.

07/10/2018, 10:41:02  node: fdfba432.d51608
msg.payload : Object
object
on: true
brightness: 70

and the response back from the light bulb

07/10/2018, 10:41:02[node: 129d4a00.ffea566]
msg.payload : Object
object
on: true
brightness: 70
reachable: true
updated: "2018-10-07T09:41:04+00:00"