Home Assistant is running on a Raspberry Pi using the standard hassio install img. SSH Server is installed and working. I can FTP into Home Assistant from my Mac, and in terminal on my Mac, I can log on at ssh root@my_HA_IP.
Let’s say I have a script in Home Assistant named watch_tv (watch_tv.yaml). How do I trigger it from my Mac?
Not sure HA REST API allows script running directly, but you can always set up an automation with MQTT trigger to run the script. I don’t have Mac, you should be able to do MQTT publish with any MQTT client from command line, or HA REST API can do that:
That stopped working when I updated Home Assistant and no matter what I’ve tried, I can’t figure out why.
I ended up settling on using Home Assistant CLI, which is included when installing “SSH & Web Terminal”. with Home Assistant CLI, this simple command works:
ssh root@MY_HA_IP hass-cli service call --arguments entity_id= script.watch_tv
So… I’ve got remote access to my HA scripts, but I feel like Home Assistant CLI runs a bit slower than when I used to send the command directly to the HA API… but like I said, I can’t figure out how to get the HA API to accept commands (I get “unauthorized” errors).
As for the HA API: I’ve tried using my HA password. I’ve tried using a Long-Lived Access Token.
Nick is correct that a token is the best way on this, but you still can use password, oh and I believe in this scenario you need to do a post. The API requires a post or get for interaction.
curl -X post https://yoururl/api/services/automation/trigger?api_password=you_password
-H {“content-type”: “application/json”}
-D {“entity_id”: “automation.your_automation”}