# Convert slider value in MQTT message

**URL:** <https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286>\
**Category:** General\
**Created:** [19 May 2019 12:06 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286 "2019-05-19T12:06:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![agoralive](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/agoralive/32/14407_2.png) [@agoralive](https://discourse.nodered.org/u/agoralive)\
**Post date:** [19 May 2019 12:06 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/1 "2019-05-19T12:06:39Z")

</div>

Hi

I have a slider in my dashboard which outputs a number between 1 - 100. I would like this number to be included into mqtt message:

"{"state":"OFF","level":"100","temperature":"50"}"

The number after level I would like this to variable from the slider while keeping the others intact.

Anybody or a way to do this?

---

<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:** [19 May 2019 12:13 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/2 "2019-05-19T12:13:26Z")

</div>

Hi,  
what does "included" mean in your case ? Is that a completely new message - or and existing message and you want to add (or change) the level value ?

---

<div class="post-metadata">

**Author:** ![agoralive](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/agoralive/32/14407_2.png) [@agoralive](https://discourse.nodered.org/u/agoralive)\
**Post date:** [19 May 2019 12:21 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/3 "2019-05-19T12:21:23Z")

</div>

> [@agoralive](#):
>
> "{"state":"OFF","level":"100","temperature":"50"}"

I want to change the value of level, if it's the entire message that needs to be changes makes no difference to me at this point

---

<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:** [19 May 2019 12:25 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/4 "2019-05-19T12:25:39Z")

</div>

for a complete message then either a simple template or function node would do the trick, for example:

```
[{"id":"8e223ffb.ea79e","type":"template","z":"439238bf.9f6608","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n{\"state\":\"OFF\",\"level\":{{payload}},\"temperature\":50}","output":"json","x":300,"y":1040,"wires":[["ebdfa204.a682f"]]}]
```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 May 2019 12:27 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/5 "2019-05-19T12:27:45Z")

</div>

Have you considered the option of using separate topics, so `your/topic/state`, `your/topic/level` and `yourtopic/temperature`? Then you won't need to merge them when publishing or split them up when subscribing.

---

<div class="post-metadata">

**Author:** ![agoralive](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/agoralive/32/14407_2.png) [@agoralive](https://discourse.nodered.org/u/agoralive)\
**Post date:** [19 May 2019 13:12 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/6 "2019-05-19T13:12:31Z")

</div>

Thank you all for this help, worked perfect 🙂

@Colin - The topics are different. They depend on the remote, the bulbs, etc...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 May 2019 14:12 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/7 "2019-05-19T14:12:29Z")

</div>

> [@agoralive](#):
>
> The topics are different. They depend on the remote, the bulbs,

Not sure why that invalidates my suggestion, it is up to you of course.

---

<div class="post-metadata">

**Author:** ![agoralive](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/agoralive/32/14407_2.png) [@agoralive](https://discourse.nodered.org/u/agoralive)\
**Post date:** [21 May 2019 17:20 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/8 "2019-05-21T17:20:41Z")

</div>

> [@agoralive](#):
>
> temperature

I understand your idea now, and that would also work. Depends on what I want to do offcause 🙂

---

<div class="post-metadata">

**Author:** ![jkmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jkmaxwell/32/29172_2.png) [@jkmaxwell](https://discourse.nodered.org/u/jkmaxwell)\
**Post date:** [26 September 2020 16:42 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/9 "2020-09-26T16:42:43Z")

</div>

@agoralive I'm trying to figure this out too but a bit new to node-red, still. Could you share how you place the slider upstream from the template and then how the template injects into the MQTT node? Sample code would be great.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2020 20:21 UTC](https://discourse.nodered.org/t/convert-slider-value-in-mqtt-message/11286/10 "2020-09-26T20:21:55Z")

</div>

> [@jkmaxwell](#):
>
> Could you share how you place the slider upstream from the template

Hi @jkmaxwell, welcome to the forum. I deduce from that question that you have only just started with node-red. If so then I strongly recommend that you watch the Node Red Essentials video playlist linked from the node red docs. A couple of hours spent doing that will allow you to answer basic questions yourself and will save a lot of time in the long run.  
When you have done that then if you are still stuck then ask again. However this thread is 18 months old so I suggest you start a new thread with the specific question you have.
