Http json request to trigger and event

Hello, I’m relative new to Home-Assistent. I created a complex Domoticz installation and configuration, but I am aware that Home assistant is more future proof.

Home assistant is running in a docker container. That is why it seems impossible, or very complex to activate a script on the host. I have a script on the host that plays a sound on a bluetooth speaker.

Domoticz is still running. It is possible to play this sound if I request this json call in the browser. Something like this:
http://192.168.188.115:8080/json.htm?type=command&param=switchlight&idx=6&switchcmd=On
The script is executed with this switch in Domoticz.

Is it possible to execute a script on the host from docker home-assistant, or is it possible to create a kind of Button, or entity to switch Domoticz with this url?

Please some advise.

The fact that HA is running in a docker does not matter.
You just want a rest command: RESTful Command - Home Assistant
This can be called from a script or automation in HA or from a switch: RESTful Switch - Home Assistant
The possibilities are endless :smiley:

Is it possible to trigger a bash script on the host then? Or do you mean I could switch Domoticz via http request?
And how would I do that?
I created a helper/Boolean switch. Is it possible to attach this http url?

What u posted is just a simple http call which can be called by either methods i posted.
Go read them as you do not need a helper.
The switch example: RESTful Switch - Home Assistant already creates a switch entity in HA you can just put on your dashboard.

Taking your http call for example:

switch:
  - platform: rest
    resource: http://192.168.188.115:8080/json.htm?type=command&param=switchlight&idx=6&switchcmd=On
    friendly_name: Play Sound on BT Speaker
    name: play-sound-bt-speaker

Which you add in your configuration.yaml

The Friendly_name: line gives a configuration error.
If I add this rest in Configuration.yaml, an entity is creates with this name. But it triggers the url constantly.
So lots of sounds trough the speaker :wink:
How could I prevent that?

The friendly_name is incorrect yes. My bad.
But looking at that url, i see that it switches something on, but never off?

http://192.168.188.115:8080/json.htm?type=command&param=switchlight&idx=6&switchcmd=On

I have no idea how the json would look for Domoticz, but you could use the command_line switch instead of the Restful

switch:
  - platform: command_line
    switches:
      play-sound-bt-speaker:
        command_on: curl -s http://192.168.188.115:8080/json.htm?type=command&param=switchlight&idx=6&switchcmd=On
        command_off: curl -s http://192.168.188.115:8080/json.htm?type=command&param=switchlight&idx=6&switchcmd=Off

Thank you! I will try that later.
According to Domoticz docs, the url looks like: /json.htm?type=command&param=switchlight&idx=8&switchcmd=<On|Off|Toggle|Stop
I will try that first.

No luck with the Rest and resource method nor with the Command-line switch. It is possible to switch Domoticz-switch, but it does not stop.

I thought it would be easier if I switch from docker to core. Then I could give homeassistant user permission to play this sound bash script.
But even that I did not find out how to create an entity in Hass that triggers this bash-script on the host.
Could someone help me with an example?
I tried command-line integration and services from dev. I’m puzzled.
Please some advise. It’s a hard way from another Home automation system.

Ok. I found out that I could do this by making ssh access from docker to host. So I changed back to docker again.

This is what I did:
Start Home assistant docker with: --network=host

docker exec -it homeassistant /bin/bash

In docker container:

docker: ssh-keygen -t rsa -b 4096 -f /config/.ssh/id_rsa
docker: ssh-copy-id -i /config/.ssh/id_rsa [email protected]

Where homeassistant is the linux-user on the host. I created a separated user for this.
Then in configuration.yaml:

shell_command:
  play_sound_host: ssh -i /config/.ssh/id_rsa [email protected] '/home/homeassistant/bin/play-sound.sh'

script:
  play_sound_host_script:
    alias: Play Sound
    sequence:
      service: shell_command.play_sound_host

Then I could add this entity to lovelace or use in a automation.