Hi all. im trying to execute a shell command to make my MBP go to sleep via a script in HAS. i have successfully setup ssh and created a script in bash to sleep the mac and it works really well. (also made the script executable)
now im trying to follow the HAS guide on shell commands (
Shell Command - Home Assistant) yet for the life of me cant get it to work
i have setup the command in config.yaml
mac_sleep: bash /root/config/scripts/office_mac_sleep.sh
and then i try to call that service yet nothing happens, logs say it ran. any clue?
Maybe permissions at the host?
Take a look at the logs on the MBP.
I assume you set up a ssh key? Follow this guide to get it to work from ha.
I’ve noticed there’s a significant number of posts looking for help on this topic and the posters all seem to struggle with a few common issues. I realized I’ve been almost copying and pasting my responses on these topics so it seemed like a good case for a community guide.
What will this cover
This guide will walk through the process of getting a command which ssh’s into another machine to get some simple data ready to be included in a command line sensor. To keep it simple I’ll use the same …
yeah ssh is setup and woks well.
I can run the command perfectly from command line on the HAS machine, ie
ssh -t macbook 'pmset sleepnow'
but the same script when I try to launch it from within a HAS script fails with an error in the logs
Integration: Shell Command (documentation, issues)
First occurred: 20:17:49 (4 occurrences)
Last logged: 20:43:21
Error running command: `bash /root/config/scripts/office_mac_sleep.sh`, return code: 127
im kinda lost on why it dosent work
thx again all really appreciate the help!
Please read that guide to properly setup the keys. You have set up keys for the terminal container only. Ha needs it’s own key that is why it is failing. The guide explains how to setup a key for ha.
turns out when using home assistant OS at least, (didnt check other options) you also need to make sure the
.ssh folder (with the private keys, config etc) is moved to
did that and if
hope other people can find the solution helpful