I have 'node-red-contrib-home-assistant-websocket' in my pallete. Using it to send command open or close door depending on temperature measure. So I have msg.payload value either 'cover.open_cover' or 'cover.close_cover' and would like to use in 'call service' node to send command to either close or open. Node has 'Service' field that requires value. It works if I put exact command like 'cover.open_cover' . But I want to use msg.payload from previous steps where I check temperature. I tried payload, msg.payload, none of which worked, hope to get help here
If I understand you right you need to set a flow context that can be then used in aflow with function or change nodes to set flow context to the message payload. I need more info. Post you flow and detail where you can exactly which information is causing problems for you and what is the ideal response from your flow.
Here is my flow. Function generates msg.payload to be either open_cover or close_cover and I would like to use that msg.payload to call service in Home Assistant. So my first attempt was below, but now I think I will just juse switch node and that should do want I wanted:
> [{"id":"7cde4c08.59790c","type":"inject","z":"123bd5e5.5a9a9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"19","payloadType":"num","x":90,"y":580,"wires":[["3d0febb5.d5c57c"]]},{"id":"3d0febb5.d5c57c","type":"function","z":"123bd5e5.5a9a9a","name":"","func":"const position = [28,26,24,20,19];\nvar current = flow.get(\"Temp-Air\") || 0;\nfor(var val of position){\n if(msg.payload>=val) break;\n}\nif(val === current){\n msg.reset = true;\n}else if(val > current){\n msg.payload = \"open_cover\";\n}else if(val < current){\n msg.payload =\"close_cover\";\n}\nflow.set(\"current\", val)\nmsg.delay = Math.abs(position.indexOf(current) - position.indexOf(val)) * 12000\n\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":660,"wires":[["d855a406.a5d668"]]},{"id":"7e7e1422.7b001c","type":"inject","z":"123bd5e5.5a9a9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":96.33332824707031,"y":623,"wires":[["3d0febb5.d5c57c"]]},{"id":"73276516.506054","type":"inject","z":"123bd5e5.5a9a9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"24","payloadType":"num","x":100,"y":660,"wires":[["3d0febb5.d5c57c"]]},{"id":"16f90a5f.05d0fe","type":"inject","z":"123bd5e5.5a9a9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"26","payloadType":"num","x":100,"y":700,"wires":[["3d0febb5.d5c57c"]]},{"id":"355bcc13.f250bc","type":"inject","z":"123bd5e5.5a9a9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"28","payloadType":"num","x":107.33332824707031,"y":742,"wires":[["3d0febb5.d5c57c"]]},{"id":"2313a34d.98b944","type":"trigger","z":"123bd5e5.5a9a9a","name":"","op1":"","op2":"stop","op1type":"pay","op2type":"str","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":600,"wires":[["a5d690bb.72771"]]},{"id":"c3652dc3.7bff38","type":"debug","z":"123bd5e5.5a9a9a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"delay","statusType":"msg","x":750,"y":660,"wires":[]},{"id":"d855a406.a5d668","type":"api-call-service","z":"123bd5e5.5a9a9a","name":"Open","server":"bbbd4030.fdb23","version":1,"debugenabled":false,"service_domain":"cover","service":"","entityId":"cover.bf9767fbce7a507ed4xp8g","data":"{\"message\":\"{{payload}}\"}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":410,"y":700,"wires":[["2313a34d.98b944"]]},{"id":"a5d690bb.72771","type":"api-call-service","z":"123bd5e5.5a9a9a","name":"Stop","server":"bbbd4030.fdb23","version":1,"debugenabled":false,"service_domain":"cover","service":"Stop_cover","entityId":"cover.bf9767fbce7a507ed4xp8g","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":590,"y":700,"wires":[["c3652dc3.7bff38"]]},{"id":"bbbd4030.fdb23","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
sorry, not sure how to post flow in one line in this forum...
surround your code with three backticks
```
like this
```
You can edit and correct your post by clicking the pencil icon.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.