Adding restart button for HA
Home Assistant release (hass --version):
0.16.1
Python release (python3 --version):
3.4.2
Component/platform: Raspberry Pi B
Description of problem: Adding Toggle or button to restart HA, at the moment I restart Raspbian completely.
Expected: I have seen a group called Home Assistant with restart button here https://github.com/brusc/Home-Assistant-Configuration , but I need a simpler option, just a click of one button no fancy scripts.
Problem-relevant configuration.yaml entries and steps to reproduce:
home_assistant:
name: Home Assistant
view: yes
entities:
- switch.home_assistant.restart
- switch.home_assistant.stop
- switch.home_assistant.start
- home_assistant.switch.turn_off
- home_assistant.switch.turn_on
Home Assistant:
- switch.home_assistant.restart
- switch.home_assistant.stop
- switch.home_assistant.start
Not sure if this has changed, but there have been several movements pushing to create a restart button in HA. The general consensus is that because HA is used on so many different types of systems, it would be difficult to create a restart button that works for everyone. And components that don't work across all systems are a no-go here.
Creating a shell_command restart button for Raspberry Pi is super easy. I don't believe you need an automation or a script. Just add this stuff to your config.
shell_command:
restart_ha: sudo service hass-daemon restart &
group:
default_view:
view: yes
entities:
- shell_command.restart_ha
Also you can call the service homeassistant/restart by clicking on the <> icon in the hamburger menu. That's what I normally use it I want to do a quick restart. :-)
Thanks, but no luck with either options when I call homeassistant/restart from the side menu: Call a service from a component. **Domain homeassistant
Service restart
CALL SERVICE**
it displays a message: service homeassistant/restart called at the bottom of the screen, but it does not restart and no changes are made after I changed some scripts etc.
I have also added the following line to my configuration.yaml file:
shell_command:
restart_ha: sudo service hass-daemon restart &
and also in my groups.yaml file I added:
home_assistant:
name: Home Assistant
view: yes
entities:
- shell_command.restart_ha
and further down in my groups.yaml file I added:
Home Assistant:
- shell_command.restart_ha
I would just like a button under my Home Assistant Group that I can click and HA must restart and reflect the changes I have made to scripts.
@GreenTurtwig What?! How long has that been there?! Who knew. Thanks for pointing me that way.
@riaandeyzel, it should be working. Try this to restart HA - go to the call services tab and click homeassistant/restart, and click the call service button. You don't need to type anything in the service data field.
To make a button in the UI you'll need to create a script and add it to your groups.
script:
restart_ha:
alias: Restart HA
sequence:
- alias: Restart HA
service: homeassistant.restart
@brusc Thank you for you reply, but I am new to home automation and programming.
I am doing something wrong somewhere. I am struggling a lot, but must admit that this is the best Home Automation App I have ever seen that is very scalable and compatible with other devices, and it looks great.
I have copied and pasted the code above in a file named restart_ha.yaml in the scripts folder. In my configuration.yaml I have added the following line: script: !include scripts.yaml and then the script.yaml contains the following"
restart_ha: !include scripts/restart_ha.yaml
refresh_devices: !include scripts/refresh_devices.yaml
and the restart_ha.yaml I have pasted the code you supplied:
script:
restart_ha:
alias: Restart HA
sequence:
- alias: Restart HA
service: homeassistant.restart
Here is my groups.yaml file which is suppose to show the restart button:
default_view:
name: The Farm
view: yes
entities:
# - group.rooms
# - group.family
- group.raspberry_pi
- group.arduino_uno
# - group.devices
- sensor.riaan_samsung_s5_battery
- sensor.kara_samsung_s4_battery
- device_tracker.riaan_s5
- device_tracker.kara_s4
- sensor.dht11_temperature
- sensor.dht11_humidity
raspberry_pi:
name: Raspberry Pi
view: yes
entities:
# - group.raspberry_pi
- sensor.arduino_a0
- sensor.dht11_temperature
- sensor.dht11_humidity
- switch.braai_led
- switch.irrigation_valve
- switch.relay_3
- switch.relay_4
- switch.relay_5
- switch.relay_6
- switch.relay_7
- switch.relay_8
arduino_uno:
name: Arduino Uno
view: yes
entities:
# - group.arduino_uno
- sensor.arduino_a0
- sensor.arduino_a1
- sensor.arduino_a2
- sensor.arduino_a3
- sensor.arduino_a4
- sensor.arduino_a5
# - switch.arduino_d0
# - switch.arduino_d1
- switch.arduino_d2
- switch.arduino_d3
- switch.arduino_d4
- switch.arduino_d5
- switch.arduino_d6
- switch.arduino_d7
- switch.arduino_d8
- switch.arduino_d9
- switch.arduino_d10
- switch.arduino_d11
- switch.arduino_d12
- switch.arduino_d13
sensors:
name: Sensors
view: yes
entities:
- sensor.dht11_temperature
- sensor.dht11_humidity
- sensor.arduino_a0
- sensor.arduino_a1
- sensor.arduino_a2
- sensor.arduino_a3
- sensor.arduino_a4
- sensor.arduino_a5
- group.weather
- sensor.weather_cloud_coverage
- sensor.weather_humidity
- sensor.weather_precip_intensity
- sensor.weather_precip_probability
- sensor.weather_pressure
- sensor.weather_summary
- sensor.weather_temperature
- sensor.weather_wind_bearing
- sensor.weather_wind_speed
weather:
name: Weather
view: no
entities:
- sensor.icon
- sensor.nearest_storm_distance
- sensor.nearest_storm_bearing
- sensor.precip_type
- sensor.weather_cloud_coverage
- sensor.weather_humidity
- sensor.weather_precip_intensity
- sensor.weather_precip_probability
- sensor.weather_pressure
- sensor.weather_summary
- sensor.weather_temperature
- sensor.apparent_temperature
- sensor.dew_point
- sensor.weather_wind_bearing
- sensor.weather_wind_speed
- sensor.visibility
- sensor.ozone
rooms:
name: Rooms
view: yes
entities:
- group.bedroom
- group.lounge
- group.bathroom
- group.kitchen
- group.spare_room
- group.braai_area
- group.garden
bedroom:
name: Bedroom
view: no
entities:
# - group.bedroom
- switch.relay_3
lounge:
name: Lounge
view: no
entities:
# - group.lounge
- switch.relay_4
bathroom:
name: Bathroom
view: no
entities:
# - group.bathroom
- switch.relay_5
kitchen:
name: Kitchen
view: no
entities:
# - group.kitchen
- switch.relay_6
spare_room:
name: Spare Room
view: no
entities:
# - group.spare_room
- switch.relay_7
braai_area:
name: lights
view: no
entities:
# - group.braai_area
- switch.braai_led
garden:
name: Garden
view: no
entities:
# - group.garden
- switch.irrigation_valve
home_assistant:
name: Home Assistant
view: yes
entities:
- shell_command.restart_ha
family:
name: family
view: yes
entities:
- group.family
- device_tracker.riaan_s5
- device_tracker.kara_a4
devices:
name: Devices
view: yes
entities:
- group.devices
- sensor.riaan_samsung_s5_battery
- sensor.kara_samsung_s4_battery
- device_tracker.riaan_s5
- device_tracker.kara_s4
weblink:
entities:
- name: Irrigation System (Remote)
url: http://10.0.0.4:8000/irrigation/html/
icon: mdi:water
- name: WebIOPi | Index (Remote)
url: http://10.0.0.4:8000/webiopi/index.html
icon: mdi:raspberrypi
- name: WebIOPi | GPIO Header (Remote)
url: http://10.0.0.4:8000/webiopi/app/gpio-header
icon: mdi:raspberrypi
- name: WebIOPi | GPIO List (Remote)
url: http://10.0.0.4:8000/webiopi/app/gpio-list
icon: mdi:raspberrypi
- name: WebIOPi | Serial Monitor (Remote)
url: http://10.0.0.4:8000/webiopi/app/serial-monitor
icon: mdi:raspberrypi
- name: WebIOPi | Devices Monitor (Remote)
url: http://10.0.0.4:8000/webiopi/app/devices-monitor
icon: mdi:raspberrypi
- name: WebIOPi | Custom (Remote)
url: http://10.0.0.4:8000/raspberrypib-custom.html
icon: mdi:raspberrypi
- name: Irrigation System (Local)
url: http://10.0.0.4:8000/irrigation/html/
icon: mdi:water
- name: WebIOPi | Index (Local)
url: http://10.0.0.4:8000/webiopi/index.html
icon: mdi:raspberrypi
- name: WebIOPi | GPIO Header (Local)
url: http://10.0.0.4:8000/app/gpio-header
icon: mdi:raspberrypi
- name: WebIOPi | GPIO List (Local)
url: http://10.0.0.4:8000/app/gpio-list
icon: mdi:raspberrypi
- name: WebIOPi | Serial Monitor (Local)
url: http://10.0.0.4:8000/app/serial-monitor
icon: mdi:raspberrypi
- name: WebIOPi | Devices Monitor (Local)
url: http://10.0.0.4:8000/app/devices-monitor
icon: mdi:raspberrypi
- name: WebIOPi | Custom (Local)
url: http://10.0.0.4:8000/raspberrypib-custom.html
icon: mdi:raspberrypi
#Weblinks:
# name: Weblinks
# view: yes
# entities:
# - group.weblink
####GROUPS####
#group:
script: !include scripts/restart_ha.yaml
#script:
# restart_ha:
# alias: Restart HA
# sequence:
# - alias: Restart HA
# service: homeassistant.restart
Home:
- group.raspberry_pi
- group.arduino_uno
- group.rooms
- group.family
- group.devices
- device_tracker.riaan_s5
- device_tracker.kara_s4
- sensor.riaan_samsung_s5_battery
- sensor.kara_samsung_s4_battery
- sensor.dht11_temperature
- sensor.dht11_humidity
- sensor.arduino_a0
- sensor.arduino_a1
- sensor.arduino_a2
- sensor.arduino_a3
- sensor.arduino_a4
- sensor.arduino_a5
Raspberry Pi:
# - sensor.dht11_temperature
# - sensor.dht11_humidity
- switch.braai_led
- switch.irrigation_valve
- switch.relay_3
- switch.relay_4
- switch.relay_5
- switch.relay_6
- switch.relay_7
- switch.relay_8
Arduino Uno:
# - sensor.arduino_a0
# - sensor.arduino_a1
# - sensor.arduino_a2
# - sensor.arduino_a3
# - sensor.arduino_a4
# - sensor.arduino_a5
# - switch.arduino_d0
# - switch.arduino_d1
- switch.arduino_d2
- switch.arduino_d3
- switch.arduino_d4
- switch.arduino_d5
- switch.arduino_d6
- switch.arduino_d7
- switch.arduino_d8
- switch.arduino_d9
- switch.arduino_d10
- switch.arduino_d11
- switch.arduino_d12
- switch.arduino_d13
Sensors:
- sun.sun
- sensor.dht11_temperature
- sensor.dht11_humidity
- sensor.arduino_a0
- sensor.arduino_a1
- sensor.arduino_a2
- sensor.arduino_a3
- sensor.arduino_a4
- sensor.arduino_a5
Weather:
- sensor.weather_cloud_coverage
- sensor.weather_humidity
- sensor.weather_precip_intensity
- sensor.weather_precip_probability
- sensor.weather_pressure
- sensor.weather_summary
- sensor.weather_temperature
- sensor.weather_wind_bearing
- sensor.weather_wind_speed
Rooms:
- group.bedroom
- group.lounge
- group.bathroom
- group.kitchen
- group.spare_room
- group.braai_area
- group.garden
Bedroom:
- group.bedroom
- switch.relay_3
Lounge:
- group.lounge
- switch.relay_4
Bathroom:
- group.bathroom
- switch.relay_5
Kitchen:
- group.kitchen
- switch.relay_6
Spare Room:
- group.spare_room
- switch.relay_7
Braai Area:
- group.braai_area
- switch.braai_led
Garden:
- group.garden
- switch.irrigation_valve
- switch.relay_8
Family:
- device_tracker.riaan_s5
- device_tracker.kara_s4
Riaan:
- device_tracker.riaan_s5
Kara:
- device_tracker.kara_s4
Devices:
- device_tracker.riaan_s5
- device_tracker.kara_s4
Home Assistant:
- shell_command.restart_ha
It also does not show the weblinks on the Home Page?
I'm not sure about the weblinks. I think for your script all you need to do is drop the script line from your restart_ha.yaml file. That "script" nomenclature is already in the main script.yaml file. So your restart_ha.yaml file should be..
restart_ha:
alias: Restart HA
sequence:
- alias: Restart HA
service: homeassistant.restart
Thanks@brusc, but still no luck. I have changed my dirctory stucture a bit to organize HA more, but I am still not sure where to copy and paste what.
I now have a configuration.yaml file containing paths to files, rather than everything in one configuration.yaml.
I have this line:
shell_command: !include shell_commands.yaml
and inside the shell_commands.yaml I got:
- restart_ha: sudo service hass-daemon restart &
Then in groups.yaml I have these entries to display the button:
sensors:
name: Sensors
view: yes
entities:
- group.home_assistant
- shell_command.restart_ha
home_assistant:
name: Home Assistant
view: no
entities:
- shell_command.restart_ha
Home Assistant:
- shell_command.restart_ha
Yeah, the multi YAML file config is nice on large setups, but it can be a bear getting it set up. At a quick glance, your shell command file doesn't look to be formatted correctly? No dash necessary. I think it should be
restart_pow: sudo service hass-daemon restart &
This probably goes without saying, but you've tested the hass-daemon restart command in the command line and made sure it works, right?
How can this be:
root@raspberrypi:~# service hass-daemon start
Failed to start hass-daemon.service: Unit hass-daemon.service failed to load: No such file or directory.
root@raspberrypi:~# service hass-daemon restart
Failed to restart hass-daemon.service: Unit hass-daemon.service failed to load: No such file or directory.
I think you need to run that command with sudo. sudo service hass-daemon restart
I am running HA as root, but running sudo service hass-daemon restart gives same error.
Failed to restart hass-daemon.service: Unit hass-daemon.service failed to load: No such file or directory. .
How is this possible, because HA runs fine except for a few small problems I run into. Does it not need this service?
If you run that command from an SSH terminal, does it work? If not, then I'd redo the daemon script process and go from there.
If it does run from a terminal interface (and this is my guess), then the issue is with HA. I'd try calling the service directly in your HA config `sudo /etc/init.d/hass-daemon restart'. Not even sure if that will do anything, but it's worth a shot.
Beyond that, I think you're into some kind of strange bug. I was having very similar issues with a command_line switch earlier this week. Something in 0.17dev/0.16 seems to have affected the commandline stuff. Haven't nailed anything down yet. It's very transient as some of my commands worked and some didn't. I'm sure it will get ironed out soon.
My working HA restart button (HA was installed with the RPi All-In-One installer, version 0.20.2).
configuration.yaml:
script: !include scripts/restart_home_assistant.yaml
group: !include groups.yaml
groups.yaml:
miscellaneous:
name: Divers
entities:
- script.restart_home_assistant
scripts/restart_home_assistant.yaml:
restart_home_assistant:
alias: Restart Home Assistant
sequence:
- alias: Restart Home Assistant
service: homeassistant.restart
The last comment provides a working solution. I will close this.