Split, select, join issue

Hi.

Can’t easily add a flow here as an example, but i’ve hit a bit of an issue i haven’t a clue how to handle in node red.

I have a report flow which puts together a long URL which is sent to voice monkey (a TTS service for alexa)

The flow often stops mid-way for the issue

Get entities in group “Normally on” →

SPLIT into messages, one device per message →

SWITCH (pass only messages where the device is off) →

TEMPLATE (Create a text string 'The is off") →

Join (messages into text string)

This works fine unless there are no devices to report, in which case there’s nothing to join and the flow stops there.

Is there another way to do this that i’m missing?

Thanks

If there is no devices to send in the message, what would you expect the message to read? It sounds like you need to add a condition to your template for when no message arrives.

Thanks for looking.

The message coming into this part of the flow is basically an array of objects. I need some way to continue if none of those objects matches my selection criteria.

The flow adds text strings to a global for later processing. After this point the contents of msg is completely irrelevant as the next step evaluates another group and populates the payload with a different array of objects.

I’ve simplified this excerpt a little. After the split, the select only sends on items which are off. If I add another branch here for on, I’ll get multiple messages (one for each device that’s on) - but i’ll only want to do anything with them IF the select never outputs an ‘off’ device.

[{"id":"2417f7d9c99f8f5f","type":"ha-get-entities","z":"46775644.dc7c28","name":"keep on devices","server":"2080cbf9.e73504","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.keep_on_devices","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":740,"y":160,"wires":[["60645b61d0d7c504"]]},{"id":"60645b61d0d7c504","type":"split","z":"46775644.dc7c28","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":940,"y":160,"wires":[["87b9f1d05b8402e2"]]},{"id":"87b9f1d05b8402e2","type":"switch","z":"46775644.dc7c28","name":"","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":1080,"y":160,"wires":[["8de23b633b41b3f1"]]},{"id":"8de23b633b41b3f1","type":"template","z":"46775644.dc7c28","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The {{payload.attributes.friendly_name}} is switched off. %20%3Cbreak%20time%3D%221s%22%2F%3E%20. ","output":"str","x":1210,"y":160,"wires":[["4e6f2cf84d511f7b"]]},{"id":"4e6f2cf84d511f7b","type":"join","z":"46775644.dc7c28","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":" ","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1440,"y":160,"wires":[["00db0c1fe882da99","d15e2e182cf28b0b"]]},{"id":"00db0c1fe882da99","type":"ha-get-entities","z":"46775644.dc7c28","name":"keep off devices","server":"2080cbf9.e73504","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.keep_off_devices","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":760,"y":280,"wires":[["5eae6ff756261986"]]},{"id":"5eae6ff756261986","type":"split","z":"46775644.dc7c28","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":960,"y":280,"wires":[["24ee9855ca2c4e73"]]},{"id":"24ee9855ca2c4e73","type":"switch","z":"46775644.dc7c28","name":"","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":1100,"y":280,"wires":[["5ddd418be2a5d63f"]]},{"id":"5ddd418be2a5d63f","type":"template","z":"46775644.dc7c28","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The {{payload.attributes.friendly_name}} is switched on.%20%3Cbreak%20time%3D%221s%22%2F%3E%20.","output":"str","x":1230,"y":280,"wires":[["122bcf90b9a4da69"]]},{"id":"122bcf90b9a4da69","type":"join","z":"46775644.dc7c28","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":" ","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1420,"y":280,"wires":[["1b06b6809c663192"]]},{"id":"07e1207082e65283","type":"inject","z":"46775644.dc7c28","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":550,"y":160,"wires":[["2417f7d9c99f8f5f"]]},{"id":"d15e2e182cf28b0b","type":"change","z":"46775644.dc7c28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t\"report\": $globalContext('SecurityReport') & payload } ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1460,"y":80,"wires":[["0c44c338aa2d9ee5"]]},{"id":"0c44c338aa2d9ee5","type":"change","z":"46775644.dc7c28","name":"","rules":[{"t":"set","p":"SecurityReport","pt":"global","to":"payload.report","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1710,"y":80,"wires":[[]]},{"id":"1b06b6809c663192","type":"change","z":"46775644.dc7c28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t\"report\": $globalContext('SecurityReport') & payload } ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1460,"y":220,"wires":[["2e4b2752590a172c"]]},{"id":"2e4b2752590a172c","type":"change","z":"46775644.dc7c28","name":"","rules":[{"t":"set","p":"SecurityReport","pt":"global","to":"payload.report","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1710,"y":220,"wires":[[]]},{"id":"2080cbf9.e73504","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

just thinking out loud - maybe the first node kicks off a timer, and the last node kicks off a reset. If there’s no reset then the timer kicks off the next part of the routine.

Seems a little clunky though - what do you think?

If we add a property to get entities to only send off and then check send empty. Move the switch node up and filter the empty message. You can then set whatever you want it to do when that happens.

[{"id":"2417f7d9c99f8f5f","type":"ha-get-entities","z":"f80b6c338afd5483","name":"keep on devices","server":"","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.keep_on_devices","valueType":"str"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":600,"y":1940,"wires":[["9e5ef29849dea52a"]]},{"id":"60645b61d0d7c504","type":"split","z":"f80b6c338afd5483","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1010,"y":1900,"wires":[["8de23b633b41b3f1"]]},{"id":"8de23b633b41b3f1","type":"template","z":"f80b6c338afd5483","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The {{payload.attributes.friendly_name}} is switched off. %20%3Cbreak%20time%3D%221s%22%2F%3E%20. ","output":"str","x":1200,"y":1900,"wires":[[]]},{"id":"07e1207082e65283","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":1940,"wires":[["2417f7d9c99f8f5f"]]},{"id":"9e5ef29849dea52a","type":"switch","z":"f80b6c338afd5483","name":"","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":true,"outputs":2,"x":770,"y":1940,"wires":[["60645b61d0d7c504"],["bc5489c32255ac17"]]},{"id":"bc5489c32255ac17","type":"debug","z":"f80b6c338afd5483","name":"do something when empty","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":1960,"wires":[]}]

thanks for looking, but ‘keep on devices’ is never empty (it’s a group defined in groups.yaml). The problem comes when there are no objects in the payload that are switched off. So we only find that out by creating the split and switching based on each object in the payload.

That’s why I moved the off condition to the get entities node. The get entities node will only send an entity from the group if it is off. If none are off it sends an empty message.