Passing payloads into entity_id

How do I put the payload from the previous node (msg.payload from a switch node for example) into the entity_id section of my service call? I have a switch node coming in with 0-100 for brightness and I want it to flow into this service node and set the brightness accordingly.

Edit: Okay so I did a little more searching and I’m not sure why this flow isn’t working. I’m getting an error on the slider because it isn’t pulling the brightness value at all and just leaving it blank in the function.

you can simplify this with a few nodes, give this a try

[{"id":"72eade60.a3685","type":"function","z":"e6ab8208.bfbbe","name":"brightness","func":"var newMsg =  {\n        payload: {\"data\":{\"brightness\":msg.payload}}\n    };\nreturn newMsg;","outputs":1,"noerr":0,"x":550,"y":660,"wires":[["811dd4cf.fbfb18"]]},{"id":"76c96925.1463b8","type":"ui_slider","z":"e6ab8208.bfbbe","name":"Slider sala","label":"I: {{value}}","group":"4bb4b124.c9376","order":6,"width":"3","height":"1","passthru":true,"topic":"","min":"3","max":"255","step":1,"x":270,"y":660,"wires":[["72eade60.a3685"]]},{"id":"811dd4cf.fbfb18","type":"api-call-service","z":"e6ab8208.bfbbe","name":"On","server":"f0aa0465.fa7ce8","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.livingroom_dimmer_level\"}","mergecontext":"","x":750,"y":660,"wires":[[]]},{"id":"4bb4b124.c9376","type":"ui_group","z":"","name":"Lights","tab":"c5e67c2b.eb40e","order":1,"disp":false,"width":"6","collapse":false},{"id":"f0aa0465.fa7ce8","type":"server","z":"","name":"Home Assistant","url":"http:\\\\xxx.xxx.xx.x:8123","pass":"password"},{"id":"c5e67c2b.eb40e","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard"}]

There is a change node where you can say

Set msg.payload.data.entity_id = anything_you_want

I’m using this command all the time as you can use it for Strings, Variables or other msg components… and the best thing is that you don’t have to worry about the formatting :slight_smile:

Tip: Put a debug-node with full msg after the service_call … this will show you the correct structure to be used with the change node… in case its not properly working

What about Current state node?
As in I am trying msg.payload.entity_id but I am getting error, Value cannot be empty.

@forums2012 did you ever find a solution to this question?