SSH issues to remote Mac

Hi Guys,

Would someone be able to assist with an issue I am having. I am attempting to create a sensor that will return data from remote Apple Mac Mini via SSH.

Steps I have taken so far:

1.) Enabled SSH on my Mac Mini
2.) Installed SSH plugin in Home Assistant
3.) Set up a passwordless access and saved the key to /config/.ssh directory
4.) copied the key to my Mac Mini
5.) Tested and confirmed I can SSH to the Mac Mini from Home Assistant Server without password prompt
6.) Found appropriate command to obtain the information required
7.) Tested the command locally from Mac Mini which returns expected results
8.) Tested the command via SSH terminal within Home Assistant also returns expected results
9.) Set up a sensor in my configuration file, see below:

  - platform: command_line
    name: Mac Mini Uptime
    command: "ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//g'"

10.) Restarted Home Assistant, Sensor is showing, however no values are listed within the entity.

Having validated passwordless access is working and the command is returning data I can only assume I have made a mistake with the configuration of my sensor.

When I check the event log the following error is listed:

Log Details (ERROR)

Logger: homeassistant.components.command_line.sensor
Source: components/command_line/sensor.py:181
Integration: command_line (documentation, issues)
First occurred: 20:06:58 (196 occurrences)
Last logged: 20:34:33

Command failed: sudo systemctl status [email protected]

If needed I am running the following:

Home Assistant 0.112.0
HassOS 4.10
Raspberry Pi 4B

Any help would be greatly appreciated, thanks in advance

Have you tested your ssh login to the mac inside the HA docker container?
That’s almost the problem with command_line integrations. When you ssh to your HA, you are not inside the HA container, but inside the supervisor, i think.

Here’s what i do to get values from a remote server.