Using bash to send a signal to homeassistant

Hello everyone!

I am using docker home assistant on ubuntu 18.04.
I want to execute a bash script through my host that access the docker container and executes a script.
I want the script to toggle a Sonoff device on and off.

I imagine something like this:

$sudo docker exec -it home-assistant /bin/toggleLight.sh

However I am not sure what should be inside toggleLight.sh.
I will then attach this command to a keyboard shortcut on my server so that I can remotely without a laptop or a phone toggle the lights on and off using a remote keyboard if available.
How can I make toggleLight.sh communicate with HA to actually toggle the light?

Regards

1 Like

I’m using mqtt for such things.

  • Setup mqtt if you don’t already have it.
  • On your host install mosquitto-clients.
  • In HA create a mqtt sensor or a switch

Now you can monitor/control everything in HA from the command line on your host.

BTW: Welcome to HA! :slightly_smiling_face:

Thanks man :slight_smile:
I will research what you just said and try it out!

By the way after a few hours i found the restful api doxumentation and used that successfully in case someone is researching this.

2 Likes

Welcome!

Have a look at this command line utility, I have used it for a while successfully and I believe it will allow you to meet your requirements. It runs from any where you can access Home Assistant via a browser inside your network as it uses same web api calls, you do not run it from within the HA container environment:

This might be even easier?

I understand the HA command you describe to only work with the Home Assistant operating system type setup. The command I described works from any machine on network that can connect to a Home Assistant server no matter what type of HA install you are doing.

Good hunting!