Trivial Python Rest API server that does one thing: give it the hostname/ip of a airport express and it'll tell you if it's currently receiving an Airplay stream.
No external dependencies.
I needed a way to find out if my Airport Express was receiving Airplay so I could automatically turn on my receiver and switch to its toslink input.
The Airport Express do have a HTTP API but it speaks Plist, a binary format that's not readily readable for most software.
Hence this little piece of server that requests the status of the Airport Express, extracts and decode the Airplay status and reports it back in JSON.
$ docker run -p 8000:8000 reefab/airport-express-status:latest
$ curl localhost:8000/<airport express hostname or IP>
{"Status": true}
Create a binary sensor.
binary_sensor:
- platform: rest
name: Airport Express Airplay Status
resource: http://localhost:8000/airport.home.arpa
scan_interval: 30
value_template: "{{ value_json.Status }}"
Use it in an automation:
- alias: 🔈 Switch on receiver if airplay is active
trigger:
platform: state
entity_id: binary_sensor.airport_express_airplay_status
to: 'on'
action:
- service: media_player.turn_on
entity_id: media_player.yamaha_receiver
- service: media_player.select_source
entity_id: media_player.yamaha_receiver
data:
source: 'AV4'