Node Red Offline Report

Hi All,

I made a node red flow to systematically check ally my devices each day at specific intervals. It seems to be working fine, but i’m having trouble with the output. I was using iphone notifications, but there is a limit to how much data you can output in those. Is there a reporting dashboard, or report feature in Home Assistant where i can populate the names of entities that are offline? I was thinking about doing it via email, but i was hoping there was something more intuitive which that i can use write in home assistant.

Here’s my code:

[{"id":"841b9631392ea7aa","type":"tab","label":"Entity Loops extra","disabled":false,"info":""},{"id":"c12b0b71b35dad0c","type":"inject","z":"841b9631392ea7aa","name":"8am Run","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 08 * * *","once":false,"onceDelay":0.1,"topic":"8am","payload":"x","payloadType":"str","x":110,"y":120,"wires":[["c36782a00bd55b83"]]},{"id":"dac5738479251dde","type":"debug","z":"841b9631392ea7aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":340,"wires":[]},{"id":"c36782a00bd55b83","type":"function","z":"841b9631392ea7aa","name":"","func":"var finalList = [];\nvar msgList = [];\n\nvar entList = [\n      //Front Office\n    'binary_sensor.doorsens_frontoffice',\n    'sensor.temp_front_office',\n    'sensor.humidity_front_office',\n    'binary_sensor.pir1_ias_zone',\n    \n\t\n    ];\n\n\n//finds all unavailable entities\n\nfor (var i = 0; i<entList.length;i++){\n    var states = global.get('homeassistant.homeAssistant.states');\n    var entState = states[entList[i]].state;\n    \n    //for testing only\n    //if (entState === \"on\") {\n    \n    if (entState === \"unavailable\") {\n        msgList.push(states[entList[i]].attributes.friendly_name);\n        } \n    else {\n        }\n    }\n\n// If unavail ents found, put in format for notification.\nif (msgList.length >0) {\n    for ( i = 0; i<msgList.length;i++){\n        if (i === 0) {\n            finalList= \"\\\\n\" + msgList[i];\n            } \n        else {\n            finalList= finalList +'\\\\n' + msgList[i];\n            }\n        }\n\n    msg.payload = finalList;    \n    }\nelse {\n    msg.payload = 'All Good';\n    }\n\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":260,"wires":[["782d9fbe594b974c"]]},{"id":"07f083210d641be8","type":"api-call-service","z":"841b9631392ea7aa","name":"Notify HA App","server":"402a621.201329c","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"The below devices are offline:<br>{{payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":220,"wires":[["dac5738479251dde"]]},{"id":"9106391d8fee6bb4","type":"inject","z":"841b9631392ea7aa","name":"12pm Run","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"12pm","payload":"x","payloadType":"str","x":110,"y":180,"wires":[["c36782a00bd55b83"]]},{"id":"7ee4d84bd6981da3","type":"inject","z":"841b9631392ea7aa","name":"4pm Run","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 16 * * *","once":false,"onceDelay":0.1,"topic":"4pm","payload":"x","payloadType":"str","x":110,"y":240,"wires":[["c36782a00bd55b83"]]},{"id":"42c33f17a440477d","type":"inject","z":"841b9631392ea7aa","name":"8pm Run","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 20 * * *","once":false,"onceDelay":0.1,"topic":"8pm","payload":"x","payloadType":"str","x":110,"y":320,"wires":[["c36782a00bd55b83"]]},{"id":"d19260b25c2db811","type":"inject","z":"841b9631392ea7aa","name":"10pm Run","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":0.1,"topic":"10pm","payload":"x","payloadType":"str","x":110,"y":380,"wires":[["c36782a00bd55b83"]]},{"id":"782d9fbe594b974c","type":"switch","z":"841b9631392ea7aa","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"All Good","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":180,"wires":[["c6630fb6f8569088"],["07f083210d641be8"]]},{"id":"c6630fb6f8569088","type":"api-call-service","z":"841b9631392ea7aa","name":"Notify HA App","server":"402a621.201329c","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"1738 System Check - {{topic}}\",\"message\":\"All Systems Online\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":600,"y":160,"wires":[[]]},{"id":"402a621.201329c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

An availability template sensor. They can be made for an individual entity, domain, or all states. 2 examples in the link are for a domain and all states.

Thanks so much for this. Quick question though. I looked through the examples. How would I make the sensor be able to tell me which devices are offline? Would I include that info in a custom attribute?

[{"id":"68d81fb0.78a26","type":"debug","z":"b0be144614c1e0d1","name":"Больше 11 минут не отвечает","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1400,"y":320,"wires":[]},{"id":"6d13bcbf.56d2f4","type":"inject","z":"b0be144614c1e0d1","name":"Каждые минуту проверяем","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":400,"wires":[["08ca118c60c2331a"]]},{"id":"8a45d50.3e87328","type":"function","z":"b0be144614c1e0d1","name":"Считаем минуты когда был онлайн","func":"let lastCon = new Date(msg.payload.attributes.last_seen);\n// @ts-ignore\nlet diffMs = Date.now() - lastCon;\nlet diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000);\nmsg.payload = diffMins\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":400,"wires":[["dae4548bed3504f1"]]},{"id":"08ca118c60c2331a","type":"api-current-state","z":"b0be144614c1e0d1","name":"Получаем состояние реле","server":"31f480d3.0e3b28","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.0xa4c138cb0eda9461_l1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","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":480,"y":400,"wires":[["8a45d50.3e87328"]]},{"id":"dae4548bed3504f1","type":"switch","z":"b0be144614c1e0d1","name":"Если больше 11 минут","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"11","vt":"str"},{"t":"lte","v":"10","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1090,"y":400,"wires":[["68d81fb0.78a26","72f2006fd801b33a"],["4ee56c69fd1205bd"]]},{"id":"4ee56c69fd1205bd","type":"debug","z":"b0be144614c1e0d1","name":"Меньше 11 минут, все ОК","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1380,"y":460,"wires":[]},{"id":"849633430fb76c65","type":"ha-entity","z":"b0be144614c1e0d1","name":"Проблемы с реле","server":"31f480d3.0e3b28","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"leak_switch_is_offline"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:alert"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":1670,"y":380,"wires":[[]]},{"id":"72f2006fd801b33a","type":"api-render-template","z":"b0be144614c1e0d1","name":"Текст сообщения об ошибке","server":"31f480d3.0e3b28","version":0,"template":"Реле протечки недоступно!","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1390,"y":380,"wires":[["849633430fb76c65"]]},{"id":"31f480d3.0e3b28","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]
1 Like