Get element entity ligth and populate input_select on HomeAssistant

first create input_select on Home Assistant for connect to flow copy on configuration.yaml

input_select: which_light: name: Select light options: - empty list - load from node red icon: mdi:format-list-bulleted

[{"id":"f4671165.d78cd","type":"inject","z":"5045577b.f5ba28","name":"Get List","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":350,"y":460,"wires":[["4985de8d.23d43"]]},{"id":"fbd46501.031d18","type":"api-call-service","z":"5045577b.f5ba28","name":"","server":"314377e1.694ce8","version":1,"debugenabled":true,"service_domain":"input_select","service":"set_options","entityId":"input_select.quale_luce","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":1040,"y":720,"wires":[[]]},{"id":"4985de8d.23d43","type":"ha-get-entities","z":"5045577b.f5ba28","server":"314377e1.694ce8","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"light","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":370,"y":540,"wires":[["7db22623.9facf8"]]},{"id":"25b96130.ab4dce","type":"template","z":"5045577b.f5ba28","name":"Data Option","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"data\": { \"options\":  [\"{{payload}}\"] }}\n","output":"str","x":870,"y":620,"wires":[["c54ca798.cd3a48"]]},{"id":"7db22623.9facf8","type":"change","z":"5045577b.f5ba28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$.payload.entity_id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":620,"wires":[["74b7c65a.04a2c8"]]},{"id":"74b7c65a.04a2c8","type":"function","z":"5045577b.f5ba28","name":"Create String with Light Entities","func":"\nvar conta = 0;\nvar i;\n var valore = \"pippo\";\n var dato = \"\";\nvar dimen = msg.payload.length;\n\nfor (  i = 0; i < dimen; i++) {\n   \n   if (i === 0) {\n       dato +='';\n   } else {\n    dato += '\"';\n   }\n     dato += msg.payload[i];\n     if (i === dimen-1){\n   dato += '';} else {\n       \n       dato += '\", ';\n   }\n}\n\n    msg.payload = dato;\n return msg;\n    \n\n","outputs":1,"noerr":0,"x":650,"y":620,"wires":[["25b96130.ab4dce"]]},{"id":"c54ca798.cd3a48","type":"string","z":"5045577b.f5ba28","name":"replace &quot","methods":[{"name":"replaceAll","params":[{"type":"str","value":"&quot;"},{"type":"str","value":"\""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":1040,"y":620,"wires":[["fbd46501.031d18"]]},{"id":"314377e1.694ce8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Flow Info

Created 5 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • function (x1)
  • inject (x1)
  • template (x1)
Other

Tags

  • input_select
  • populate
  • set_option
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option