Insert payload in function node

Hi,

I want to tell the battery level of my iPhone through my Sonos speakers. What should the function node look like that the battery level (here 55) is shown instead of {payload}?

Thanks.

[{"id":"9dd41be525a05db3","type":"function","z":"083ed1e120af109e","name":"Sprachinhalt","func":"msg.payload = \"Der Akkuzustand deines iPhones beträgt nur noch {payload} %\";\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":140,"wires":[["38f5a12e132886e9","4361cd46ccfa6eb8"]]},{"id":"962152fd5a3c8f07","type":"api-current-state","z":"083ed1e120af109e","name":"iPhone Akku","server":"d6e1a14d.333e1","version":3,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.dennis_iphone_12_mini_battery_level","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":530,"y":140,"wires":[["9dd41be525a05db3"]]},{"id":"9b922ba69f8917f5","type":"inject","z":"083ed1e120af109e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":140,"wires":[["962152fd5a3c8f07"]]},{"id":"38f5a12e132886e9","type":"debug","z":"083ed1e120af109e","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":80,"wires":[]},{"id":"4361cd46ccfa6eb8","type":"ttsultimate","z":"083ed1e120af109e","name":"Sonos Wohnzimmer","voice":"Hans#engineType:standard","ssml":false,"sonosipaddress":"192.168.178.31","sonosvolume":"30","sonoshailing":"Hailing_Schulglocke.mp3","config":"014de07df5901c80","property":"payload","propertyType":{},"rules":[],"playertype":"sonos","speakingrate":"1","speakingpitch":"0","unmuteIfMuted":true,"elevenlabsStability":"0.5","elevenlabsSimilarity_boost":"0.5","x":940,"y":140,"wires":[[],[]]},{"id":"d6e1a14d.333e1","type":"server","name":"Home Assistant","addon":true},{"id":"014de07df5901c80","type":"ttsultimate-config","name":"AWS Amazon Polly","noderedipaddress":"AUTODISCOVER","noderedport":"1980","purgediratrestart":"leave","ttsservice":"polly","TTSRootFolderPath":""}]

Inside a function you use the message path.

const message = "My new message, battery is " + msg.payload + " percent.";
msg.payload = message;
return msg;
1 Like