Node-red

From Simon's Help System
Revision as of 15:34, 15 January 2024 by Simon (talk | contribs)
Jump to navigation Jump to search

Node Red

Backup all flows using 'export' and save as a file (flows.json)


If you have to remove any old versions of node-red

sudo systemctl disable nodered.service
sudo npm -g remove node-red
rm -R ~/.node-red

Update node

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

Then to update node-red go to https://nodered.org/docs/getting-started/raspberrypi


and run the bash script

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
node-red-start

If all good stop it and restart as a service with

node-red-stop
sudo systemctl enable nodered.service
sudo systemctl status nodered.service

Examples of node-red for Home Assistant

DBCG5AO.png
[{"id":"66c50c00.a3c8c4","type":"inject","z":"74ddc16c.19655","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":112,"y":1056,"wires":[["87111b5d.423eb8"]]},{"id":"87111b5d.423eb8","type":"ha-get-entities","z":"74ddc16c.19655","server":"351c96ee.9dc3aa","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"}],"output_type":"random","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":262,"y":1056,"wires":[["f1234263.eed69"]]},{"id":"541ec87b.02a788","type":"delay","z":"74ddc16c.19655","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"20","randomLast":"30","randomUnits":"minutes","drop":false,"x":592,"y":1056,"wires":[["5cec6ee6.cfa5a"]]},{"id":"f1234263.eed69","type":"api-call-service","z":"74ddc16c.19655","name":"Turn on Light","server":"351c96ee.9dc3aa","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\"}","render_data":true,"mergecontext":"","output_location":"","output_location_type":"none","x":422,"y":1056,"wires":[["541ec87b.02a788"]]},{"id":"5cec6ee6.cfa5a","type":"api-call-service","z":"74ddc16c.19655","name":"Turn off Light","server":"351c96ee.9dc3aa","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"{{payload.entity_id}}\"}","render_data":true,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":758,"y":1056,"wires":[[]]}]
Node-red5.png

If the token expires Node-Red will stop talking to Home Assistant. You need to create a new token. First click on my photo icon at the bottom left of the HA page.

Node-red3.png

Then create a new long lived access token. Copy the token into notepad++ as it will dissapear from view after creatioon.

Node-red4.png

Next go into node-red and click on any home assistant link, you only need to do this once. Click on the blue connector. This open the main dialogue.

Then click on the pencil to the right of server Home assistant

Then enter the URL and new token into the dialogue box.

Node-red2.png