3.1.23 • Published 6 months ago

@petro-kushchak/homebridge-homepod-radio v3.1.23

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

HomePod Mini Radio

HomePod Mini Radio is a Homebridge plugin for streaming radio urls and audio files to a Homepod (Mini or OG) or an Apple TV.

Streaming radio to HomePod

The main idea is to stream audio to the HomePod or Apple TV using the pyatv AirPlay library.

  • Automatically stops streaming when HomePod is used by another app
  • Sometimes audio streaming stops, so plugin automatically restarts it

!NOTE As the plugin is streaming via AirPlay, it should work with any AirPlay enabled speakers. YMMV.

Requirements

  • NodeJS (>=8.9.3) with NPM (>=6.4.1)
  • pyatv (>=0.13) which require python (>= 3.8)

For the HomePod you can specify device MAC address or device name.

Usage Example:

Multiple radio accessories support

!IMPORTANT Each radio speaker must be added to Home app separately with Homebridge pin pairing

Config example:

{
    "platform": "HomepodRadioPlatform",
    "serialNumber": "20020105:00",
    "homepodId": "<homepod id or name>",
    "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. The plugin supports an optional metadataUrl parameter and tries to fetch JSON in the following format (example: 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": ""
      },
      ...
  ]

The plugin then

  • Enriches the radio stream with singer and song values from the retrieved metadata
  • Enriches the radio artwork with the image downloaded using the cover metadata URL

!NOTE Due to some bugs/limitations in tvOS 16/17, HomePods are not showing this info.

Audio file playback

The plugin allows to start file playback either through a add switch accessory (see below) or it can be triggered from a webhook.

Make sure your audio files are available to the Homebridge server, for example by downloading them to the server:

$ 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 the plugin to play files from /home/pi/media by setting the mediaPath property:

  "mediaPath": "/home/pi/media",

Switch accessory for audio file playback

This feature adds a switch accessory in the audioFiles section for each audio file you want to stream

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

Supported audio file formats are mp3, wav, flac, and ogg.

You can also specify an .m3u playlist file to stream multiple files:

    "audioFiles": [
        {
            "name": "Relaxing Mood",
            "fileName": "death_metal.m3u",
            "volume": 85
        }
    ]

The .m3u file format is just a list of audio files:

# My playlist

# Metallica, 1991
Nothing Else Matters.mp3

# Master Of Puppets, 1986
Master Of Puppets.mp3

# Ride The Lightning, 1984
For Whom The Bell Tolls.mp3

!NOTE Comments starting with # and empty lines are ignored.

Webhook for audio file playback

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

Example:

  • Homebridge is running on host "homebridge.local"
  • hello.mp3 file is on the same server on /var/www/media
  • Plugin's "httpPort" is set to 4567
  • Plugin's "mediaPath" is set to /var/www/media

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

You can specify the playback volume level, by adding it to the end of the playback URL: http://homebridge.local:4567/play/hello.mp3/75

Audio file playback automation example

  • Configure automation to play file
    • Select/Create automation in Home app
    • Tap "Select Accessories and Scenes..."
    • At the botton tap "Convert to Shortcut"
    • Create shortcut: Screenshot
    • Test shortcut

HomePod access setup

In the Home app settings:

  • Tap the Homes and Home Settings button.
  • Tap Home Settings > Allow Speaker & TV Access, then choose "allow everyone"
  • Important! Reboot the HomePod

Siri support (works on iPhone/iPad)

  • Create shortcut with name (for example) "Start Radio"
  • Select "Control Home" action, check corresponding speaker and in "Media" section select "Resume Audio") Screenshot
  • Say "Hey Siri, start radio" on iPhone/iPad (on HomePod mini Siri does not run it properly)

Dependencies

PyATV lib

For streaming to the HomePod the plugin uses pyatv (https://pyatv.dev). Follow these setup instructions for RaspberryPi/Linux. If installing on a different platform, adjust as needed.

Install python3:

sudo apt-get install python3

Install pip3:

sudo apt-get install python3-pip

Install pyatv:

pip3 install pyatv

Make atvremote available for homebridge:

sudo ln -s /home/pi/.local/bin/atvremote /usr/local/bin/atvremote

Installing the PyATV lib in the Homebridge Docker container

The Homebridge Docker image comes with the latest version of python pre-installed. At the time of writing, the image is based on Ubuntu 22.04, with Python 3.10.12 included.

To avoid having to reinstall pyatv every time the container is recreated (for example when updating the Homebridge image), Homebridge provides the startup.sh script, which is executed after the Docker container is finished starting up. Add the following line to the end of startup.sh:

pip3 install pyatv

You can do this from the command line (using your favorite editor) and finding the script in the Homebridge config folder. Alternatively you can edit it from the Homebridge UI, by going to Settings, Startup & Environment, Startup Script. If you edit the script from the UI or after the container has started, you will need to restart the container.

Setup steps

Starting with various OS versions, Apple devices have started generating, by default, a new random MAC address for each wireless network they connect to. The HomePod Identifiers are based on the MAC address and while it will not change every time the HomePod reconnects to your home wifi, resetting a HomePod will indeed generate a new randomized MAC address and therefore new HomePod Identifiers. If this happens, you will have to update the plugin configuration.

Due to Apple's use of MAC address randomization and simply to make it easier to setup and read the plugin configuration, you can use the HomePod name (as displayed in the Home app) in the HomePod Id field, as well as any of the HomePod Identifiers. If you use the HomePod name, you will have to update the plugin configuration if you change it in the Home app.

Find HomePod Identifiers:

Scan for devices:

atvremote scan

Select one of Identifiers values from the chosen device (or the Name value):

       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

Stream URL format

The easieast path would be to get the 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.

Scan for devices:

atvremote scan

Select 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

!IMPORTANT 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 disappears 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.

3.1.3

7 months ago

3.1.2

7 months ago

3.1.1

8 months ago

3.1.0

8 months ago

3.1.7

7 months ago

3.1.5

7 months ago

3.1.4

7 months ago

3.1.9

7 months ago

3.1.8

7 months ago

3.1.12

7 months ago

3.1.11

7 months ago

3.1.14

7 months ago

3.1.13

7 months ago

3.1.16

7 months ago

3.1.15

7 months ago

3.1.18

6 months ago

3.1.17

6 months ago

3.0.1-beta.3

1 year ago

3.0.1-beta.4

12 months ago

3.1.10

7 months ago

3.1.23

6 months ago

3.1.22

6 months ago

3.1.21

6 months ago

3.1.20

6 months ago

3.1.19

6 months ago

3.1.0-beta.2

8 months ago

3.1.2-beta.2

8 months ago

3.1.0-beta.3

8 months ago

3.1.2-beta.1

8 months ago

3.1.0-beta.4

8 months ago

3.1.0-beta.5

8 months ago

3.1.0-beta.6

8 months ago

3.1.0-beta.7

8 months ago

3.0.1-beta.2

2 years ago

2.0.16-beta.0

2 years ago

3.0.1-beta.0

2 years ago

3.0.1-beta.1

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

2.0.15

2 years ago

2.0.14

2 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.1-beta.0

3 years ago

1.2.17-beta.0

3 years ago

1.2.16-beta.4

3 years ago

1.2.16-beta.5

3 years ago

1.2.16-beta.3

3 years ago

1.2.16-beta.0

3 years ago

1.2.15-beta.0

3 years ago

1.2.16-beta.2

3 years ago

1.2.16-beta.1

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.12

3 years ago

1.2.13

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

3 years ago

1.2.0

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.42-17

4 years ago

1.1.42-16

4 years ago

1.1.42-15

4 years ago

1.1.42-14

4 years ago

1.1.42-13

4 years ago

1.1.42-12

4 years ago

1.1.42-11

4 years ago

1.1.42-10

4 years ago

1.1.42-9

4 years ago

1.1.42-7

4 years ago

1.1.42-6

4 years ago

1.1.42-5

4 years ago

1.1.42-4

4 years ago

1.1.42-3

4 years ago

1.1.42-2

4 years ago

1.1.42-1

4 years ago

1.1.42

4 years ago

1.1.42-beta.3

4 years ago

1.1.42-beta.2

4 years ago

1.1.42-beta.1

4 years ago

1.1.41

4 years ago

1.1.42-beta.0

4 years ago

1.1.40-beta.6

4 years ago

1.1.40-beta.5

4 years ago

1.1.40-beta.4

4 years ago

1.1.40-beta.3

4 years ago

1.1.40-beta.2

4 years ago

1.1.40-beta.1

4 years ago

1.1.40-beta.0

4 years ago

1.1.36-alpha.4

4 years ago

1.1.36-alpha.3

4 years ago

1.1.36-alpha.2

4 years ago

1.1.36-alpha.1

4 years ago

1.1.35-beta.6

4 years ago

1.1.35-beta.5

4 years ago

1.1.35-beta.4

4 years ago

1.1.35-beta.3

4 years ago

1.1.35-beta.2

4 years ago

1.1.35-beta.1

4 years ago

1.1.34

4 years ago

1.1.35-beta.0

4 years ago

1.1.34-beta.7

4 years ago

1.1.34-beta.6

4 years ago

1.1.33

4 years ago

1.1.34-beta.5

4 years ago

1.1.34-beta.4

4 years ago

1.1.34-beta.3

4 years ago

1.1.34-beta.2

4 years ago

1.1.34-beta.1

4 years ago

1.1.34-beta.0

4 years ago

1.1.32-beta.0

4 years ago

1.1.31-beta

4 years ago

1.1.30-beta

4 years ago

1.1.29-alpha

4 years ago

1.1.28-alpha

4 years ago

1.1.27-beta

4 years ago

1.1.26-alpha

4 years ago

1.1.25-alpha

4 years ago

1.1.24-alpha

4 years ago

1.1.23-alpha

4 years ago

1.1.22-alpha

4 years ago

1.1.21-alpha

4 years ago

1.1.20-alpha

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17-beta

4 years ago

1.1.16-beta

4 years ago

1.1.15-beta

4 years ago

1.1.13-beta

4 years ago

1.1.12-beta

4 years ago

1.1.11-beta

4 years ago

1.1.10-alpha

4 years ago

1.1.9-alpha

4 years ago

1.1.8-alpha

4 years ago

1.1.7

4 years ago

1.1.6-beta

4 years ago

1.1.5-beta

4 years ago

1.1.4-beta

4 years ago

1.1.3-beta

4 years ago

1.1.2-beta

4 years ago

1.1.1-beta

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.49

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago