Notify about missing entities or devices in my flows

Hi, I’m using the node-red flows but I couldn’t find an answer in the forum.

I have many devices in the flows as trigger or event receivers like switches. Given that I delete or rename a device it could exist in one of the flows.

I’d like to iterate all used home assistant entities in all my flows. In case one of them is unknown it should send a notification.

Is there any idea how I could establish that?

There is no way to isolate the entities used in NR. You can create a binary sensor in HA that will report missing entities.

https://www.home-assistant.io/integrations/template/#rate-limiting-updates

There is also spook and thewatchman that can monitor for missing entities and more.

Spook is installed already. It can report missing entities when they are used in any of the dashboards or automations. This, I have already in place. But how should spook or other tools in HA know if a deleted device was removed by mistake or whether there is a link in node-red? The check is required in NR.

Seems I need to accept …

In NR there is the catch node. I haven’t used it but it is supposed to catch errors on flows.

the catch I know as well. Unfortunately it’s only reactive. I’d like to scan proactive, especially after I did reconfigurations or updates.

The template sensor checks every entity every 60 seconds. It’s not instant but it’s close.

what template sensor are you talking about? In Homeassistant, or is there something similar in node-red?

The one in the first link I posted

In the below example, re-renders are limited to once per minute because we iterate over all available entities:

template:
  - binary_sensor:
      - name: "Has Unavailable States"
        state: "{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}"

as mentioned before. I don’t have a problem to find the devices in HA.

I want to see imediate when a flow in node-red is broken because a device was deleted. The trigger needs to be a logic in NR.

Sample, I have a flow which reacts when I’m leaving my flat. It should switch of the TV.

Now the TV device in HA was deleted by whatever reason. In HA the TV is not included in any of the dashboard. Spook wouldn’t find anything. Also a template with criteria state unavailable wouldn’t find as the device doesn’t exist anymore. When its not there it doesn’t have any “unavailable” or “unknwon” sensor.

What you can do in that case is spook provides a sensor.entities With that you can monitor if an entity goes missing. To get what is missing you would first need to have a stored array of entities.

Use this flow once to create the flow store. You should have storing context to file enabled to protect against data loss during updates/restarts/reinstall.

[{"id":"3c2a41f167326d70","type":"ha-get-entities","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":1,"rules":[{"property":"state","logic":"is","value":".*","valueType":"re"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"flow","outputLocation":"allEntities","outputResultsCount":1,"x":430,"y":300,"wires":[["69ae8a458e09dfb2"]]},{"id":"abddc0e1ef6c4fe5","type":"inject","z":"0a325c35fc29f44e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":300,"wires":[["3c2a41f167326d70"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

This will trigger when sensor.entities drops and will return the missing entity.

[{"id":"69ae8a458e09dfb2","type":"debug","z":"0a325c35fc29f44e","name":"debug 203","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":380,"wires":[]},{"id":"45c602ac6c7934fd","type":"ha-get-entities","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":1,"rules":[{"property":"state","logic":"is","value":".*","valueType":"re"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":430,"y":380,"wires":[["406da598d134693a"]]},{"id":"cee949d4a515fe6c","type":"trigger-state","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":4,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.entities","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<","comparatorValueDatatype":"prevEntity","comparatorValue":"state"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":140,"y":380,"wires":[["45c602ac6c7934fd"],[]]},{"id":"406da598d134693a","type":"function","z":"0a325c35fc29f44e","name":"function 25","func":"let arr1 = msg.payload;\nlet arr2 = flow.get(\"allEntities\");\nconst difference = arr2.filter(({ entity_id: id1 }) => !arr1.some(({ entity_id: id2 }) => id2 === id1));\nflow.set(\"allEntities\", arr1);\n\nmsg = {};\nmsg.payload = difference;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":380,"wires":[["69ae8a458e09dfb2"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Finally if the entities sensor increases, store new array.

[{"id":"9e18b8390a1c2110","type":"trigger-state","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":4,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.entities","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":">","comparatorValueDatatype":"prevEntity","comparatorValue":"state"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":140,"y":480,"wires":[["7bdd22807d2d8dae"],[]]},{"id":"7bdd22807d2d8dae","type":"ha-get-entities","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":1,"rules":[{"property":"state","logic":"is","value":".*","valueType":"re"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"flow","outputLocation":"allEntities","outputResultsCount":1,"x":430,"y":480,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Since node-red-contrib-home-assistant-websocket version 0.68 I got all my missing entities listed in the upper right corner of nodered:
Bildschirmfoto_2024-08-27_18-02-42

Which version are you using?!

What version is that? Is this the HA plugin? I’m using the full Node-Red installation as stand alone in latest version (4.0.2). Unfortunately the warning doesn’t show up there.

I couldn’t find any config to activate such a warning. Did you configure anything or was it activated during update or rollout? I guess it’s only available in the HA plugin but not in the default standalone with activated home-assistant library.

Anyway it wouldn’t be what I was searching but better than nothing.

I’m using stand alone Node Red 4.0.2 aswell. It is this node I’m using for my home assistant, running in a different VM.