Switch to start systemctl service?

This doesn’t seem to work…? any reason why? the service is on the same host as home-assistant

  - platform: command_line
    name: ssh_turn_on_off_ring_alarm_mqtt
    switches: 
      ring_alarm_mqtt:  
        command_on: "systemctl start ring-alarm-mqtt.service"

Only error: Command failed: systemctl start ring-alarm-mqtt.service

Do you have any other command line switches that work? If you try to run the command from a terminal from within hassio does it work there?

I ask because I think that hassio doesn’t have the necessary permissions to run commands on the host. At least that’s the way it is on non-hassio systems running in Docker. So since hassio also runs in docker it’s safe to assume that is the case there as well.

I have successfully set up my HA to run commands on the host but I have no idea how to do that in hassio.

Ther can be a couple of generic reasons.

  1. Likely the command is not running as the root user

  2. Depending on the execution environment, you may need to add the full path to the systemctl command.

thanks, i did the full path, but it still didn’t work…, how do i add home-assistant as root?

What type of installation do you have?
If it is Hassio or Docker based, Home Assistant is not running on the host OS, but in a Docker container.

docker in ubuntu

Home Assistant is running in a separate environment that only uses the Ubuntu Linux kernel.
It has no control over the Ubuntu systemd services.

A Hassbian or a Python venv installation does not have those restrictions.

@finity

This works in Hassio on HassOS. I didn’t have to do anything special to get it to run.

  - platform: command_line
    name: RPi CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    value_template: "{{ value | multiply(0.001) | round(2) }}"

i can’t change the permissions?

$ sudo chown “$USER”:"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx “$HOME/.docker” -R

https://docs.docker.com/install/linux/linux-postinstall/

Systemd services and commands are not in the Docker container. They are outside it, in the Ubuntu OS…

so it should work then? i am a linux newb, finally getting a hang of some of the commands

Home Assistant is not running on Ubuntu. It is running in the Docker container.

It would be like you were running a Windows virtual machine on Ubuntu and wanted to run the systemd command from the Windows VM. It cannot be done.

anyway i can bypass this? can i have a python script in ubuntu that can be called from hassio/docker container?

i didn’t see it but which docker install are you running? hassio or non hassio?

They stated Docker in Ubuntu. Either way Home assistant is running in a Docker container, correct?

yes, but according to @jazzyisj above it looks like the functionality for running commands on the host might be built in in Hassio. But if they are running regular HA in Docker then there are other steps that need to be taken.

and it adds more confusion since they didn’t install it with an image but installed it manually. Which may change things too.

They stated Hassio on HassOS though, not Ubuntu.

I think you are speaking of @jazzyisj?

Yes, they said that.

I was just trying to clarify from the OP which version they use since it might make a difference on how (or if) I can help them.

In Post 6, I think

doesn’t say anything about hassio or not.