I often find that some devices are unavailable. I do not know why this is happening, but seems somewhat random. Today all of the TP-Link light switches were MIA. And it seems to happen to entire integrations. All Matter, all TP-Link, etc. All I have to do is reload each device to bring them all back on line. Is there an easy way to scan for offline devices and reload them, so I am not finding something broken and having to fix it?
Sure, create an automation with a trigger based on the data going unavailable, the use the action to reload the integration.
Here’s an example from my system. The use case is my ecobee thermostat reporting via HomeKit sometimes stops updating. So if I don’t get an update for a couple of hours an alert in generated. That alert triggers this automation if it’s active for 1 minute. Then it logs a warning, reloads the integrations, waits 30 seconds and then determines if the reload was successful. If not it send a message to my phone. So you’d want to change the trigger. Also you don’t want many automations firing at the same time reloading the same integration.
`- id: ts reload integration downstairs_thermostat_temperature
alias: ts reload integration downstairs_thermostat_temperature
trigger:
- platform: state
entity_id: alert.al_ts_downstairs_thermostat_temperature_latency
to: "on"
for: "00:01:00"
id: latency
action:
- service: system_log.write
data:
level: warning
message: "downstairs_thermostat_temperature offline reloading integration {{trigger.id}}"
logger: ts
- service: homeassistant.reload_config_entry
target:
entity_id: sensor.downstairs_thermostat_temperature
continue_on_error: true
- delay: "00:00:30"
- if:
- "{{ is_state('alert.al_ts_downstairs_thermostat_temperature_latency','idle') and has_value('sensor.downstairs_thermostat_temperature') }}"
then:
- service: system_log.write
data:
message: "downstairs_thermostat_temperature online after reloading integration"
logger: ts
else:
- service: notify.sms_telegram_admin
data:
message: "downstairs_thermostat_temperature still offline after reloading integration"`