I’ve set up a Pi Zero with gpio pins by a door, with a reed switch on the door. When the door opens, I can get it to turn a Hue light on.
What I can’t get working is that when the door opens, I want to play audio from a Pi3 (located in another room), via its audio jack.
Both Pis are running Home Assistant, and I’ve been trying to use MQTT (the Broker is on the Pi3) and/or Mopidy, but could be looking in the wrong direction.
binary_sensor:
- platform: rpi_gpio
device_class: opening
ports:
14: Front Door
mqtt:
broker: 192.168.0.244
I use a switch with ssh to play audio on a remote Pi from HA, it might be of use to you:
- platform: command_line
switches:
three_d_print_begun_via_pirate_audio:
command_on: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'play -G -v1 Bell-tone-mono.mp3 && play -G -v2.5 Your-3D-Prints-Begun.mp3'
friendly_name: 3D Print has Begun
The ssh bits before the pi@... part are to suit Hassio, and you’ll have to copy over ssh keys of course. You won’t need them unless you’re using Hassio.
The play command comes from SoX, installed with:
sudo apt install sox libsox-fmt-mp3
Then when the event happens you can use the switch.turn_on service in a script or automation:
Assuming a central MQTT broker (or two bridged ones), I’d probably go for some MQTT: The first Pi sets a value, the second runs some automation based on it.
You could also directly access the REST API of the 2nd Pi from the 1st one, and let it do almost anything.
For me, MQTT turned out to be the most robust (and de-coupled) solution. We run bridged MQTT over many hundreds of kilometres, and it has never failed us.