Can HA process external web commands when an event is triggered?

I am currently using Vera and I’m able to run the below code as part of a scene to have an announcement that the The_Front_Door_Has_Been_Opened for example.
http://192.168.0.2/sound.php?file=The_Front_Door_Has_Been_Opened&volume=100

I have a RaspPi running apache, php, and MPG123 and when I execute the above URL it will play a mp3 file named The_Front_Door_Has_Been_Opened.mp3 to a sound device (currently a powered speaker).

The MP3 files were created here http://www.fromtexttospeech.com. and live on the RPi in /var/www/html/audio/

Can HA process external web commands when an event/sensor/scene is triggered?

At the very least you can run a shell command in an automation, so your example could be performed via curl.

See https://www.home-assistant.io/components/shell_command/

so…

# Example configuration.yaml entry
shell_command:
 curl: http://192.168.0.2/sound.php?file=The_Front_Door_Has_Been_Opened&volume=100

No.

shell_command:
   playfrontopen: curl http://192.168.0.2/sound.php?file=The_Front_Door_Has_Been_Opened&volume=100

thanks, I’ll try it

i’m testing this from another RPi I have and the “sound playing RPi” doesn’t play the file.

pi@AlexaPi:~ $ curl http://192.168.0.201/sound.php?file=lgo&volume=100
[1] 5053
pi@AlexaPi:~ $

after installing apache, php, and MPG123 you create a sound.php file

    <?php
   $filename = $_GET['file'];   
   $volume = $_GET['volume'];
   exec("sudo mpg321 -g ".$volume." /var/www/html/audio/".$filename.".mp3");   
?>

at that point you can use a browser on any machine to test and go to a test url
http://192.168.0.201/sound.php?file=lgo&volume=100
if that works you add this code to the lower gate open scene on the vera

    local http = require("socket.http")
-- 5 Second timeout
http.TIMEOUT = 5
result, status = http.request("http://192.168.0.201/sound.php?file=lgo&volume=95")

and when the scene exicutes the “sound playing RPi” server plays the sound.
I tried to execute the curl command from a terminal on several other RPis I have running and no joy.

Try quoting the url.

By the way why are you using sudo?

Quotes work, with and without sudo
thanks

You should probably avoid raising privileges unless actually needed, so avoid sudo where possible.

Glad it is working.

well, I got my RPi and it’s up and running hassos.
I added the vera as a controler and it discovered all my “stuff”
While the documentation is fairly clear, it also assumes a higher level of understanding of the code.
I’m having trouble creating from scratch the equivalent of a vera scene.
I think if I had an example of HA/Vera code I could figure it out.
Can anyone using a vera show an example of your code with vera devices.
Basically, as and example, I’d like to turn on a light for 5 minutes after a door is opened and then off again and run this HA code along with the light coming on

so when door is opened
Kitchen_Door 1
Vera Device Id 65
binary_sensor.kitchen_door_1_65

turn on this light
Kit_Eat_Light_Dim
Vera Device Id 14
light.kit_eat_light_dim_14

run this code
shell_command:
playkitchenopen: curl “http://192.168.0.200/sound.php?file=kdo&volume=100

I think what you are looking for is automations, as opposed to scenes. The docs have many examples.

I’ve been digging around in the uploaded examples in https://www.home-assistant.io/cookbook/#example-configurationyaml.

I’m changing my example to the Laundry Room door and turning on two lights then off again. I’d also like to execute the
playkitchenopen: curl “http://192.168.0.200/sound.php?file=kdo&amp;volume=100” code but I’m not sure where or if I can in the blow code so I’m throwing it in as a WAG

auto.yaml
#################################################################
## Home Automation Related
#################################################################

- id: Laundry_Room_lights_on
  alias: 'Turn on inside and outside LaundryRoom lights when door opened'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.laundyroomdoor_113
      from: 'off'
      to: 'on'
  condition:
    - condition: or
      conditions:
       - condition: state
         entity_id: cover.LaundryRoom #<--- not sure what this was about,
         state: 'closed'
       - condition: state
         entity_id: sun.sun
         state: 'below_horizon'
  action:
     service: light.turn_on
     data:
       entity_id: light.laundryroom_29
     data:
       entity_id: light.lrdooroutside_123  
       brightness: 255
     shell_command:
       playLRDopen: curl “http://192.168.0.200/sound.php?file=ldo&volume=100”

and then turn the two lights off after a few minutes

- id: Laundry_Room_lights_off
  alias: 'Turn off Laundry room lights'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.laundyroomdoor_113
      to: 'off'
      for: '00:00:30'
    - platform: state
      entity_id: light.laundryroom_29
      to: 'on'
      for: '00:05:00'
      entity_id: light.lrdooroutside_123
      to: 'on'
      for: '00:05:00'
  condition:
    - condition: state
      entity_id: light.laundryroom_29
      state: 'on'
    - condition: state
      entity_id: light.lrdooroutside_123
      state: 'on'
  action:
     service: light.turn_off
     entity_id: light.laundryroom_29
     entity_id: light.lrdooroutside_123

I’m I doing this right or do I need to call a script?

I’m thinking I don’t need this part as it came from a GARAGE door example

```
       - condition: state
         entity_id: cover.LaundryRoom #<--- not sure what this was about,
         state: 'closed'
```

here is a test automation I plan to try when I get home

- id: frontdoor_open
  alias: Front Door Open
  trigger:
    - platform: state
      entity_id: binary_sensor.front_door_1_67
      from: 'off'
      to: 'on'
  action:
    - service: shell_command.play_fdo_sound

shell_command:
  play_fdo_sound: curl "http://192.168.0.201/sound.php?file=fdo&volume=100"

does it look right?

Why not using Restful Command in an automation?

so…

- id: frontdoor_open
  alias: Front Door Open
  trigger:
    - platform: state
      entity_id: binary_sensor.front_door_1_67
      from: 'off'
      to: 'on'
  action:
    - service: rest_command.play_fdo_sound

rest_command:
  play_fdo_sound:
    url: 'http://192.168.0.201/sound.php?file=fdo&volume=100'

looks good :slight_smile: IMO

or maybe even…

  action:
    - service: rest_command.play_fdo_sound
        url: 'http://192.168.0.201/sound.php?file=fdo&volume=100'

or…

  action:
    - service: rest_command.play_fdo_sound
      data:
        url: 'http://192.168.0.201/sound.php?file=fdo&volume=100'

Nope, url is a definition parameter… data values can be passed as GET/POST paramter when you need dynamic url building…
just

action:
    - service: rest_command.play_fdo_sound

should do it…