I have a flow (below) that read the status of a number of entities (temperature and energy data, repeats every 5 minutes if heating is on, and then appends the data to a CSV file for later analysis. This works well.
But I’m repeating a lot of the same stuff with the risk of making errors and it makes expanding the measurements cumbersome. I would like to have list so I only use one current state node which loops through the list and returns the state as msg.entity_name. This could be passed on to other nodes and reused eg. when formatting data and setting column names in csv.
Is there a way to make a list of the entities and then loop through them in a current state node?
[{"id":"23fa32681c0bc9d2","type":"file","z":"19045bc6.44c9c4","name":"","filename":"/config/www/data_test.csv","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":1060,"y":420,"wires":[["3e9bbcde15490c73"]]},{"id":"5aa1215751f20f82","type":"inject","z":"19045bc6.44c9c4","name":"","props":[{"p":"timestamp","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"*/5 11-15 * * *","once":false,"onceDelay":"30","topic":"","x":110,"y":160,"wires":[["48630c8d0d97382d"]]},{"id":"e6ad1014c0b5d462","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.hottub_daily_energy","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"daily_energy","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":540,"y":260,"wires":[["3d3daa32c9fd31d2"]]},{"id":"6c9d6e25bd36273f","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.hottub_heatpump_water_out_temp","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"heatpump_water_out_temp","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":1570,"y":180,"wires":[["e6ad1014c0b5d462"]]},{"id":"52bd0b22a9e32532","type":"debug","z":"19045bc6.44c9c4","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1630,"y":400,"wires":[]},{"id":"fa3c0b589375760d","type":"csv","z":"19045bc6.44c9c4","name":"","sep":",","hdrin":false,"hdrout":"once","multi":"mult","ret":"\\n","temp":"date,time,heatpump_water_in_temp,heatpump_water_out_temp,daily_energy,Ambient temp,hottub temp,temp feels like,temp open weather map,hottub_electric_heater","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":790,"y":420,"wires":[["23fa32681c0bc9d2"]]},{"id":"1ac0022f482d1919","type":"function","z":"19045bc6.44c9c4","name":"Set data","func":"var now = new Date();\n\nmsg.payload = {\n \"date\" : msg.date,\n \"time\" : msg.time,\n \"heatpump_water_in_temp\" : msg.heatpump_water_in_temp,\n \"heatpump_water_out_temp\" : msg.heatpump_water_out_temp,\n \"daily_energy\" : msg.daily_energy,\n \"Ambient temp\" : msg.ambient,\n\t\"hottub temp\" : msg.hottub_temp,\n\t\"temp feels like\" : msg.temp_feels_like,\n\t\"temp open weather map\" : msg.openweathermap_temp,\n\t\"hottub_electric_heater\" : msg.hottub_electric_heater\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":420,"wires":[["fa3c0b589375760d"]]},{"id":"9701b8ebe746e53f","type":"moment","z":"19045bc6.44c9c4","name":"","topic":"","input":"datetime","inputType":"msg","inTz":"Europe/Copenhagen","adjAmount":0,"adjType":"days","adjDir":"add","format":"HH:mm","locale":"C","output":"time","outputType":"msg","outTz":"Europe/Copenhagen","x":720,"y":180,"wires":[["e7174c32b04aa340"]]},{"id":"354b4697424dc2de","type":"moment","z":"19045bc6.44c9c4","name":"","topic":"","input":"datetime","inputType":"msg","inTz":"Europe/Copenhagen","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD/MM/YYYY","locale":"C","output":"date","outputType":"msg","outTz":"Europe/Copenhagen","x":480,"y":180,"wires":[["9701b8ebe746e53f"]]},{"id":"e7174c32b04aa340","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.hottub_heatpump_water_in_temp","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"heatpump_water_in_temp","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1070,"y":180,"wires":[["6c9d6e25bd36273f"]]},{"id":"3d3daa32c9fd31d2","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.hottub_heatpump_ambient_temp","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"ambient","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":980,"y":260,"wires":[["c5c0898e2266f3f1"]]},{"id":"c5c0898e2266f3f1","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.hottub_heater","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":1390,"y":260,"wires":[["c1a165ac5ab4d89a"]]},{"id":"c1a165ac5ab4d89a","type":"change","z":"19045bc6.44c9c4","name":"read current_temperature","rules":[{"t":"move","p":"data.attributes.current_temperature","pt":"msg","to":"hottub_temp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1690,"y":260,"wires":[["9376fc56d10ec97d"]]},{"id":"9376fc56d10ec97d","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.openweathermap_feels_like_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"temp_feels_like","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":610,"y":340,"wires":[["91da5970e3ee1008"]]},{"id":"91da5970e3ee1008","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.openweathermap_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"openweathermap_temp","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":1100,"y":340,"wires":[["a56781509aa88c1f"]]},{"id":"c5a299f5b2060413","type":"api-current-state","z":"19045bc6.44c9c4","name":"stop loop when heat is off","server":"785585e5.21e4ec","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.hottub_heat_on_off","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":490,"y":500,"wires":[["e30887c9ce602666"],[]]},{"id":"3e9bbcde15490c73","type":"delay","z":"19045bc6.44c9c4","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1360,"y":420,"wires":[["c5a299f5b2060413"]]},{"id":"e30887c9ce602666","type":"link out","z":"19045bc6.44c9c4","name":"","mode":"link","links":["92aca86d95475ddf"],"x":1115,"y":500,"wires":[]},{"id":"92aca86d95475ddf","type":"link in","z":"19045bc6.44c9c4","name":"","links":["e30887c9ce602666"],"x":75,"y":300,"wires":[["48630c8d0d97382d"]]},{"id":"a56781509aa88c1f","type":"api-current-state","z":"19045bc6.44c9c4","name":"","server":"785585e5.21e4ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.shelly1_98cdac2da2b2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"hottub_electric_heater","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":1510,"y":340,"wires":[["1ac0022f482d1919"]]},{"id":"48630c8d0d97382d","type":"change","z":"19045bc6.44c9c4","name":"Timestamp","rules":[{"t":"set","p":"datetime","pt":"msg","to":"$now()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":180,"wires":[["354b4697424dc2de"]]},{"id":"785585e5.21e4ec","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
Thanks,
Kasper