The ability to Schedule a ReBoot

It would be nice, to have the Ability to schedule Home Assistant to reboot. Or even better, a choice of rebooting just HA or the OS.

There is an option to restart HA, I use that to restart every other day, as I found that HA became unstable after about 3 days.

# restart HA to keep it fresh
- alias: Restart HA
  trigger: 
    platform: time
    at: "02:00:00"  
  condition:
    condition: time
    weekday:
    - sun
    - wed
    - fri
  action:
    - service: homeassistant.restart
14 Likes

Thanks, this will work for me.

I run this automation last night, now this morning i noticed that my Home-Assistant had not come back up again.
In the log i see that at 02:00 the service stopped, and then it did not come back up again.
I edited your script to run every day.

- alias: Restart HA
  trigger: 
    platform: time
    at: "02:00:00"  
  condition:
    condition: time
    weekday:
    - sun
    - mon
    - tue
    - wed
    - thu
    - fri
    - sat
  action:
    - service: homeassistant.restart

I am running the latest hassbian and have hassctl to, maybe there is a way to add a hassctl restart to crontab, but im not shure how its supose to be written…

2 Likes

Sounds like you have an issue in your general configuration. Did you check the log?
Does it come back up if you completely reboot the pi?

Also, if you want it every day you can just remove the condition (doesn’t hurt to have it the way you have it, just cleaner without and same effect)

I know, the issue that I have, is with the WiFi Signal. It not as strong as it should be, which causes two other problems. First, the WiFi signal is so weak, that I can not use the Sonoff Basic switch,unless it is less then 5 feet from the WiFi router. And the Main Issue(that is causing all the errors), is one of my 4 Amcrest Cameras, is about 25 feet from the Router. And with the Weak Signal, it keeps dropping off the network, which causes the Errors in the Log.

I already did a warranty replacement of the Linksys router, and still get the same issue. I need to find someone, that can do an RF analyse of my house. To find out, what is causing the RF Noise, that is stepping on my WiFi Signal. Once I fix this issue, I should be able to run the Sonoff Basic switch and Camera without any issues.

One question, about the above Automation, after creating it, I get a “Restart HA” switch in the Main screen. Am I correct, in assuming, if I turning the switch to OFF, the automation will stop running???

To answer your last question: yes, you can turn off the automation that way. It should be in the same list as all your other automations. You can even trigger it from there if you like.

I’m afraid I can’t give you any tips on the wifi issues your describing. When I mentioned checking the log I was referring to your comment that HA wasn’t coming back up after a restart. Do you still have that problem?

So, are you saying that if I cycle the switch Off, then On, it will trigger the automation?

As for the WiFi signal, I know what I need to do, find someone that has a RF Noise analyzer.

And when Home Assistant, doesn’t boot up, it is usually because I type in something wrong in the Configuration file. Like putting a capital letter, where it don’t belong.

If you click on the automation there is a trigger button that you can use to trigger the automation. Useful for testing.

A picture is worth a 1000 words…

Your right, a Picture is worth a 1000 words… Until I saw your picture, all I saw was;

image

I never though there was another Box to look at, Thanks again…

Excuse the necrobump :ghost: but for others who come here like me to find an automation to restart home assistant…

If you want it to run every day, you simply omit the condition: section altogether

- alias: Restart HA
  trigger: 
    platform: time
    at: "02:00:00"  
  action:
    - service: homeassistant.restart

Thanks to the original posters though for leading me to the solution I needed :+1:

4 Likes

how to define to have a resrart every 3 hours due to xiaomi disconnection problem

Try

trigger:
  platform: time_pattern
  hours: "/3"
action:
  - service: homeassistant.restart
1 Like

How do I use this code?
Do I just copy it into my configuration file?
Link this? When I do that, the config file says that the code is incorrect.

@Grebhoven — that code is an automation. It needs to go into your automations.yaml, although if you use the UI as well, it may get overwritten. See here:

<soapbox>

If you’re having to reboot periodically, something is wrong with your setup. If you know that, and are happy to use this as a workaround, perhaps because you’re reliant on some flaky bit of IoT hardware that can’t be fixed, then fine.

But please don’t be “infected” by the “old Windows” mindset that a regular reboot is necessarily a good thing — HA, like any properly-designed system, can easily have weeks or months of uptime without needing to be “refreshed”.

I’d be against a feature to easily allow scheduled rebooting.

</soapbox>

1 Like

Copied it into automation file, now this error:

HA really isn’t a project where you can blindly copy-paste stuff and expect it to work.

Remove the two spaces before - alias: Restart HA then reload automations. Is 10:45 really the best time to restart it?

2 Likes

Hi @grebhoven , @troon has already pointed you in the right direction - the code is an automation and needs to be put in that section.
I do agree with his ‘soapbox’ point though - I posted this four years ago when HA was a lot less stable, I haven’t needed it for a long time by now as HA has improved considerably and is much more stable. Try to figure out what bit of your setup causes instability and fix that, instead of forcing reboots.

1 Like

Also agreed. As everyone know, a restart once in a while is good for every computer. My RPi is no different @DDK.

As for the time @Troon - This was a ‘test’ set up to see if the reboot actually happens. I will set it somewhere at night. And as for your comment the HA is not a project to copy/paste code: Everyone started somewhere :slight_smile:

this video may be helpful: