Convert slider value in MQTT message

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?

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 ?

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

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"]]}]

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.

Thank you all for this help, worked perfect :slight_smile:

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

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

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