I’m ok with Node-Red just a complete noob when it comes to JSON.
Very simple question I think - I’m trying to output a message via the notify section of the call service node. It works perfectly but I would like to include with the messsge the msg.topic and/or msg.payload - how might I do that using JSON ?
Setting the nodes as depicted below makes the entries for ‘target device’, ‘message’ and ‘topic’ flexible.
[{"id":"7570bf674d461c67","type":"change","z":"6e482e4a.3e4bb","name":"Set Message Attributes - Water level","rules":[{"t":"set","p":"message","pt":"flow","to":"The water level in the Levoit is low","tot":"str"},{"t":"set","p":"target1","pt":"flow","to":"media_player.juan_s_2nd_echo_dot","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2224.881149291992,"y":3297.7382736206055,"wires":[["9bc405081feedc93"]]},{"id":"5cf6083f62385aa7","type":"api-call-service","z":"6e482e4a.3e4bb","name":"Notify Target1 (Alexa) with Message","server":"8a3231e1.3f0e1","version":5,"debugenabled":false,"domain":"notify","service":"alexa_media","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":true,"outputProperties":[],"queue":"none","x":2769.8811569213867,"y":3297.7382736206055,"wires":[[]]},{"id":"9bc405081feedc93","type":"function","z":"6e482e4a.3e4bb","name":"Create Alexa Alert","func":"\nvar target = flow.get('target1')\nvar message = flow.get('message')\n\nvar payload = \n{\n \"data\":\n {\n \"target\": `${target}`,\n \"message\": `${message}`,\n \"data\": {\n \"type\": \"announce\"\n }\n }\n}\nmsg.payload = payload\nmsg.topic = `${target}`\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2505.238456726074,"y":3297.2028732299805,"wires":[["5cf6083f62385aa7"]]},{"id":"8a3231e1.3f0e1","type":"server","name":"Hassio","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
Thank you so much ! - Ive imported your flow and altered it to fit. Works a treat now !
1 Like