# Hue Magic - Dashboard slider for brightness ?!

**URL:** https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727
**Category:** General
**Created:** [6 October 2018 00:21 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727 "2018-10-06T00:21:43Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)
#### Post date: [6 October 2018 00:21 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/1 "2018-10-06T00:21:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [6 October 2018 00:56 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/2 "2018-10-06T00:56:42Z")

</div>

Join the party... 🥳  
[https://discourse.nodered.org/search?q=hue%20slider](https://discourse.nodered.org/search?q=hue%20slider)

---

<div class="post-metadata">

### Author: ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)
#### Post date: [6 October 2018 01:15 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/3 "2018-10-06T01:15:01Z")

</div>

Hi @shrickus

I’m at the party ,with drink in hand 🙂 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.

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [6 October 2018 08:54 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/4 "2018-10-06T08:54:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 October 2018 10:10 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/5 "2018-10-06T10:10:15Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [6 October 2018 10:34 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/6 "2018-10-06T10:34:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [6 October 2018 10:40 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/7 "2018-10-06T10:40:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [6 October 2018 14:10 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/8 "2018-10-06T14:10:48Z")

</div>

> [@cflurin](#):
>
> BTW a similar setting for the `mqtt-in` node would be helpful.

YES PLEASE!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 October 2018 14:17 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/9 "2018-10-06T14:17:23Z")

</div>

Somewhat offtopic

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [6 October 2018 14:46 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/10 "2018-10-06T14:46:24Z")

</div>

> [@dceejay](#):
>
> Somewhat offtopic

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

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 October 2018 15:05 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/11 "2018-10-06T15:05:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [6 October 2018 15:21 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/12 "2018-10-06T15:21:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)
#### Post date: [6 October 2018 19:04 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/13 "2018-10-06T19:04:40Z")

</div>

> [@dceejay](#):
>
> template node can also output JSON directly if you want

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 ?

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [7 October 2018 00:52 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/14 "2018-10-07T00:52:21Z")

</div>

There's a (confusing) little hint, hidden in the default template:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/fa4250310d1a4604ae581b5c7ba93d3355d33d1a.png)

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.

---

<div class="post-metadata">

### Author: ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)
#### Post date: [7 October 2018 09:46 UTC](https://discourse.nodered.org/t/hue-magic-dashboard-slider-for-brightness/3727/15 "2018-10-07T09:46:22Z")

</div>

Many thanks for that nugget @shrickus 😁

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"
```
