Auto Reboot when Home assistant can't be reach from Outside

Dear to All,

I face some issue with my Home assistant, which is I can’t reach it from outside even if nothing special occurs. Or maybe it happened, but I’m unable to figure what it is.

Since i’m out of Home, I’m unable to restart manually the Raspberry or the Home assistant I can’t reach.

So I’m looking for a way to restart automatically the Home assistant server as soon as he is not reachable from the outside, so he will remains always reachable at all time.

I know the commande restart, but don’t know on which parameter to trigger it, what kind of test I need to ask the Home assistant to do ?

Thank you for your help

Simplest all-purpose solution is to get a smart plug of some kind - one that can be controlled remotely through its own app.

I took a different approach to the keeping HA ‘fresh.’ I set up a sensor in HACS garbage collection every other day. I then wrote an automation to have it reboot. The development is so fast (NOT COMPLAINING) that I find it essential.

- id: '1628610016959'
  alias: Reboot HA Core
  description: Reboot home assistant at 11:57:19 pm
  trigger:
  - platform: time
    at: '23:57:19'
  condition:
  - condition: state
    entity_id: sensor.boot_hacore # <-- the garbage collection sensor
    state: '0'
  action:
  - service: homeassistant.restart
  mode: single

Shelly has a nice interface for smartphones if you want to go @Stiltjack route.

I suppose it all depends on why HA is unreachable - and more particularly on whether it knows there’s a problem. If it doesn’t there aren’t many options.

1 Like

Thank you very much for your help, but if you do have an idea to take a look on the log and see what happened when my HA become unreachable ?? I’m curious to see if I can fix the issue ?

The reboot solve it all the time, but let him unreachable till the reboot …

Thanks AllHailJ for your proposal, just wanted to understand what this code is ? what is the sensor.boot_hacore ?

So it reboot Home Assistant at 23:57:19 everyday if the condition is met, which is the state of sensor.boot_hacore to zero ?

Thanks you for your help.

The code is an automation built to boot the core every other day. The trigger is set at ~23:57 and the condition is created from a garbage collection sensor.

‘sensor.boot_hacore’ is created in the Garbage Collection Integration. See here for information.

https://github.com/bruxy70/Garbage-Collection

I integrated using hacs.

The sensor as created in yaml

garbage_collection:
  - name: Boot HACore
    frequency: "every-n-days"
    first_date: '2021-08-08'  
    period: 2 #<-- Boot every other day

the state of sensor.boot_hacore will be 0 every other day. It will be 1 on the off days and if I had a longer interval it would be 2.

It will reboot HA core every other day at 23:57:19. It takes about two minutes to reboot the core. The 19 is just crap and I don’t remember why I chose it at 19 seconds probably because it is a prime number.

Hope this answers your questions.

1 Like

I would guess you need to diagnose more. Is it down because your home router is not connecting to the outside? Or just HA? You could use the reboot code above with a.ping sensor trigger like one to 8.8.8.8 but if your router is down that would mean nothing unless you put the same on the router.

I just tried with the latest version of Home assistant, it gives me an error and refuses the addition of the Sensor. :wink:

Nothing has changed for me except upgrades and I still use all the same automations. It rebooted last night as it was supposed to. I have upgraded HA to this:

‘’’
System Health

Version core-2021.12.10
Installation Type Home Assistant OS
Development false
Supervisor true
Docker true
User root
Virtual Environment false
Python Version 3.9.7
Operating System Family Linux
Operating System Version 5.10.91
CPU Architecture x86_64
Timezone America/*******

Home Assistant Community Store

GitHub API ok
Github API Calls Remaining xxxx
Installed Version 1.20.0
Stage running
Available Repositories 1010
Downloaded Repositories 30

Home Assistant Supervisor

Host Operating System Home Assistant OS 7.2
Update Channel stable
Supervisor Version supervisor-2021.12.2
Docker Version 20.10.9
Disk Total xx.x GB
Disk Used xx.x GB
Healthy true
Supported true
Board ova
Supervisor API ok
Version API ok
Installed Add-ons Terminal & SSH (9.3.0), Log Viewer (0.12.2), Z-Wave JS (0.1.52), AppDaemon 4 (0.8.1), Check Home Assistant configuration (3.9.0), Samba share (9.5.1)

If you can’t reach if from outside your LAN then the easiest way I could think to do it is to use a google calendar entry to trigger the request.

Create a 1 minute entry like “HAReboot” about 5 mins in the future to give HA time to sync with the calendar.
Then have an automation monitor the calendar for that “HAReboot” entry, “Wait for Time to pass” for 2 minutes to prevent it from repeating after restart and then action the core restart.

That should do it

2 Likes