petro-kushchak / homebridge-homepod-radio

MIT License
35 stars 2 forks source link

HomePod mini radio support

Homebridge accessory for streaming radio to the Homepod mini

Streaming radio to HomePod (mini)

Main idea is to stream to the HomePod mini (or Apple TV) with the following command:

ffmpeg -i <streamUrl> -f mp3 - | atvremote --id <homepodId> stream_file=-

Note: After plugin v2.0 - streaming and retry logic moved to stream.py script

Requirements

For the HomePod you need to specify device Mac address.

Usage Example:

Multiple radio accessories support

Note: each radio speaker must be added to home separately with homebridge pin pairing

Config example:

{
    "platform": "HomepodRadioPlatform",
    "serialNumber": "20020105:00",
    "homepodId": "<homepod id>",
    "httpPort": 7654,
    "mediaPath": "/media/homepod",
    "enableVolumeControl": true,
    "radios": [
        {
            "name": "BBC - Radio 1",
            "radioUrl": "http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one",
            "artworkUrl": "https://ichef.bbci.co.uk/images/ic/1920x1080/p05d68tx.jpg",
            "autoResume": true,
            "onSwitch": true
        }
    ],
    "audioFiles": [
        {
            "name": "Alert",
            "fileName": "police.mp3",
            "volume": 85
        }
    ]
}

Radio metadata support

Some radios provide metadata about currently played tracks. Plugin support optional metadataUrl parameter and tries to fetch JSON in format (example URL: https://o.tavrmedia.ua/rokscla):

[
      {
            "stime": "15:29:21",
            "time": "15:29",
            "singer": "Billy Joel",
            "song": "Honesty",
            "cover": "https://www.radioroks.ua/static/img/content/cover/0/38/500x500.jpg"
      },
      {
            "stime": "15:25:38",
            "time": "15:25",
            "singer": "Fleetwood Mac",
            "song": "Everywhere",
            "cover": ""
      },
      ...
  ]

Then plugin:

  1. updates radio stream with fetched singer/song data
  2. updates radio artwork with image downloaded using cover

Note: due to some bugs/limitations TvOs 16/17 (beta) on HomePod are not showing this info

Audio file playback

Switch accessory for the audio file playback

This feature adds additional switch accessory for each audio file from audioFiles section:

    "audioFiles": [
        {
            "name": "Alert",
            "fileName": "police.mp3",
            "volume": 85
        }
    ]

Web hook for audio file playback

You should use homebridge server name or IP (default for Homebridge server is homebridge.local) to invoke playback with URL

Example:

Then you can trigger playback of hello.mp3 even from browser by navigating to: http://homebridge.local:4567/play/hello.mp3

Audio file playback automation example

HomePod access setup

In the Home app settings:

Siri support (works on iPhone/iPad)

Dependencies

ffmpeg lib

sudo apt-get install ffmpeg

PyATV lib

For streaming to the HomePod we are using pyatv (https://pyatv.dev). Setup instructions (for RaspberryPi)

Docker image with preinstalled dependencies (ubuntu)

Docker image build based on oznu/homebridge:ubuntu (with ffmpeg&Homebridge preinstalled)

Mode info: https://hub.docker.com/r/pkushchak/homebridge-pyatv/tags

Setup steps

Identify HomePod mini ID:

Stream URL format

The easieast would be to get streaming url from your favorite radio playlist (usually .m3u file) Example For BBC Radio: https://gist.github.com/bpsib/67089b959e4fa898af69fea59ad74bc3

Known issues

1. Pairing setting for the HomePod (fixed by HomePod access setup step):

Make sure your HomePod has Pairing: NotNeeded set for RAOP protocol. Command

atvremote scan

Should show for your device:

Services:
 - Protocol: Companion, Port: 49152, Credentials: None, Requires Password: False, Password: None, Pairing: Unsupported
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded

Note: streaming will not work if you get Pairing: Disabled or Pairing: Unsupported

2. HomePod playback errors

Sometimes (quite rarely) playback fails and in the logs there are errors like:

  pyatv.exceptions.HttpError: RTSP/1.0 method SETUP failed with code 500: Internal Server Error

Typically this error dissapears after HomePod restart.

3. Streaming to stereo pair

Looks like this is not supported at the moment by pyatv

4. Speaker accessory controls

With iOS 15 Homekit does not support volume control and start/stop for speaker accessory (at least for speakers exposed by Homebridge). So I'd suggest to enable switch accessory for each radio

TODO list

  1. Switch accessory for the audio file playback (with loop support)
  2. Play audio file on the HomePod with provided url
  3. Radio streaming to the multiple HomePods