Homebridge accessory for streaming radio to the 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
For the HomePod you need to specify device Mac address.
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
}
]
}
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:
singer
/song
datacover
Note: due to some bugs/limitations TvOs 16/17 (beta) on HomePod are not showing this info
Plugin allows to add swtich accessory to start file playback, also file playback can be triggered from web hook
Download your files to Homebridge server. For example download hello.wav
$ mkdir -r /home/pi/media
$ <downlaod files to /home/pi/media>
$ ls /home/pi/media
-rw-r--r-- 1 pi pi 94622 Jan 10 16:46 hello.wav
Configure plugin to play files from /home/pi/media, set mediaPath property:
"mediaPath": "/home/pi/media",
This feature adds additional switch accessory for each audio file from audioFiles
section:
"audioFiles": [
{
"name": "Alert",
"fileName": "police.mp3",
"volume": 85
}
]
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
In the Home app settings:
sudo apt-get install ffmpeg
For streaming to the HomePod we are using pyatv (https://pyatv.dev). Setup instructions (for RaspberryPi)
sudo apt-get install python3
sudo apt-get install python3-pip
pip3 install pyatv
sudo ln -s /home/pi/.local/bin/atvremote /usr/local/bin/atvremote
Docker image build based on oznu/homebridge:ubuntu (with ffmpeg&Homebridge preinstalled)
Mode info: https://hub.docker.com/r/pkushchak/homebridge-pyatv/tags
atvremote scan
Name: HomePod
Model/SW: HomePod Mini, tvOS 15.2
Address: 192.168.1.7
MAC: F4:22:F0:10:33:71
Deep Sleep: False
Identifiers:
- F4:22:F0:10:33:71
- F422F0103371
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
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
orPairing: Unsupported
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.
Looks like this is not supported at the moment by pyatv
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