Reboot pi from hass.io

Hi. Long story short is there any way I can automate rebooting my raspberry pi (the pi itself, not hass.io) on a schedule using hass.io?

So far I have found no solution: cron on the pi doesn’t work (or there is no true access to it when sshing to a pi running hass.io); there is no sudo in hass.io and it can’t be installed, so you can’t run a shell script to reboot; etc etc etc

does hassio host reboot work? If so, you should be able to add it to a script and add to an automation to fire it off.

Isn’t that only available from the command line?

Sorry, I wasn’t thinking straight.

You should be able to call the service hassio.host_reboot.

2 Likes

Awesome! Works! Thanks!

1 Like

@fezfox are you able to write this up if you came up with a solution?

yes I did:

- id: reboot_pi
  initial_state: true
  alias: 'Reboot pi daily'
  trigger:
  - platform: time
    at: '03:00:00'
  action:
  - service: hassio.host_reboot
5 Likes

Apologies for resurrecting an older thread, but could you be more specific on how you implemented the solution described above? Did you add this in the configuration.yaml file?

Thanks… Fairly new to HA and a lot of the discussions are more than a little confusing since they are written by people who obviously know what they’re doing, while those of us who don’t (or barely) are struggling to learn. :slight_smile:

1 Like

This is an automation. So you could

  1. include it directly in configurations.yaml, as above preceeded by automation:
  2. more typically, people put all their automations as above in a single filed called automations.yaml and refer to that file in configurations.yaml like this:
automation: !include automations.yaml
  1. In my case, I actually have an automations folder and that is in a file called system.yaml and every file in that folder is included with this line in configurations.yaml:
automation: !include_dir_merge_list automation/

TL;DR;

add the above to your configrations.yaml file, indented after automations:

4 Likes

Thank you for the clarification! HomeAssistant can be rather daunting in the beginning. :thinking:

1 Like

Hi,
I am also new in the HA community. I have some issues with my HA and the MotionEye. I have som WIFI cameras connected. After some hours the PI end up in a deadlock. The only way to get i started again is to pull the A/C plug. To solve this I am trying to reboot the PI, say every 6-8 hours. I see that one can automate the reboot. I am usure how I shall edit the configurations.yaml to get the automatic reboot of the PI and HA. Is ther someone that can give me some advice on the editing?
Thanks!

Hi Patrik,
Sure there is.
Here is how i’ve done mine. And I’ll explain a bit, even if it is common knowledge for some, maybe it will help others to understand better how they can create their own automation.

  1. Go to Configuration
    image

  2. Go to Automations.
    image

  3. Click on " + ADD AUTOMATION" button on the lower right corner
    image

  4. The automation wizard will appear.
    I will break it into sections so it will be easy to explain.
    You need to provide some information:

First section - Description and info:

  • Give it a name, for example: “Night reboot”,
  • Add a description, for example: “HA 4:00 AM reboot”
  • Select a mode on how the automation will work - I recommend that you use “Single”
  • And a switch to enable/disable that automation (in case you later want to stop using it but not delete it)

Second section - Triggers:
In this section you basically have the option to select what will “activate” (trigger) the automation.
In your case you will use Time as a trigger, at a specific time.

Nb: you can have multiple triggers for more advanced automation (for example, trigger this automation if the camera does not reply to ping for 30 seconds… but this will be more advanced)

Third Section - Conditions:
For now you can leave this without any conditions.

For future, you can add here conditions for this to run

Case: “Allow to run this automation only if the system has been up for at least 24h” In case you did a previous manual reboot that day, it will not require to reboot the host again

Fourth section - Actions
This is actually the section that you specify WHAT your automation will do based on the previous information.

In the Action Type, you need to select: “Call service” - this means that HA will try run a command that you will specify in the “Service” field

In your case it is a simple service call to reboot the host (can be a VM or a PC or a Pi etc) of your home assistant OS:

Here is the actual command that you need to add hassio.host_reboot

In the end it should be something like this picture:

For other types of automation you can select a different “Action type”, you can set a value, or add a delay etc…

For example you can set the lights to a specific value based on a specific time.
And after a delay, you can set them to another value (color or brightnes etc)

think of it like this

1 Action - turn the bedroom light on at 20 percent
2 Action - wait 30 minutes
3 Action - set the bedroom light at 50 percent
and so on and so on…

Hope this helps you and others.
And don’t hesitate to: read the docs / other people’s scripts / try yourself / ask here for help :slight_smile:

Best regards
Bogdan

7 Likes

Hi Bogdan!
Thank you for your great help! Fantastic step by step instruction! Just what I needed. I have now done my first automation with your help.
Many Thanks!! :slight_smile:
Best regards
Patrik

1 Like