Dacp / daapd / iTunes support

Thats possible . I have it setup this way.

thats my /etc/systemd/system/spotify-connect.service

[Unit]
Description=Spotify Connect
After=network-online.target
[Service]
Type=idle
User=pi
ExecStart=/home/pi/librespot --backend pipe --device /home/pi/music/spotify -n spotifyConnect --cache /tmp > /dev/null 2>&1
Restart=always
RestartSec=10
StartLimitInterval=30
StartLimitBurst=20
[Install]
WantedBy=multi-user.target

The important part is the --backend pipe --device /home/pi/music/spotify part which tells Spotify connect to use a named pipe as output device. This named pipe has to be created before and of course should be located inside the library that forked-daapd is indexing.

if you include

        # Watch named pipes in the library for data and autostart playback when
        # there is data to be read. To exclude specific pipes from watching,
        # consider using the above _ignore options.
        pipe_autostart = true

in /etc/forked-daapd.conf then forked-daapd will automatically start the playback when librespot fills the pipe (that is when you select librespot in spotify as an output.

You can use whatever Remote app to select the speakers forked-daapd will stream to or you can use mpd to do so via a shell script.

I actually configured switches in home-assistant for that purpose:

  - platform: command_line
    switches:
        airplay_loop:
        command_on: "/usr/bin/mpc -h 192.168.178.94 enable 3243"
        command_off: "/usr/bin/mpc -h 192.168.178.94 disable 3243"
        command_state: "/usr/bin/mpc -h 192.168.178.94 outputs | grep Bad"
        value_template: '{{ value == "Output 3243 (Bad) is enabled" }}

As you probably can guess you can get the speaker ids by using /usr/bin/mpc outputs

hope this helps.

1 Like

Thanks so much! I will work on that this weekend.

Okay wow. This was so much easier than I thought it was! Took me like an hour.

Thanks for your tips man! :slight_smile:

In case it helps anyone else, a dummies guide:

  • Install raspotify (wrapper) on the pi to make it easy on yourself: https://github.com/dtcooper/raspotify
  • Create the pipe. I did mkfifo /opt/music/spotify. This is the --device.
  • Make sure the pipe and music dir is rw for raspotify
  • Add options in /etc/default/raspotify, remove --backend alsa from its systemd config
  • Install forked-daapd:
  1. Add this line to /etc/apt/sources.list:
    deb http://www.gyfgafguf.dk/raspbian jessie/armhf/
  2. Run sudo apt-get update and then sudo apt-get install forked-daapd
  • Install mpc
  • Edit /etc/forked-daapd.conf:
  1. pipe_autostart = true
  2. directories = { "/opt/music" }

Then you just use mpc to turn on the speakers. Super easy.

1 Like

@snizzleorg Do you only ever use your speaker with one account?

I would like to be able to share the speaker between me and my wife. She has her own Spotify Premium account.

I am thinking of starting up two librespot instances and pointing them to the same pipe (if this is possible). When my wife selects her speaker ‘chimpyWife_Speaker’, the Spotify HA component can trigger an automation on ‘playing’ and if source = ‘chimpyWife_Speaker’. The automation would pause my stream (if ‘playing’ to ‘chimpy_Speaker’) thus avoiding the two streams from overlapping.

Another automation would take of the other way around, when she is playing something and I wish to use the speaker.

edit

Just checked and named pipes can accept multiple inputs. Sweet. Time to test.

I think it works with multiple accounts when you do not specify the account while running librespot.

I have to try…

Yeah you can put in discovery mode but that’s not an acceptable solution to me because the Source in Hass eventually disappears whereas when you’re logged in it remains there permanently, even when it’s not locally available.

ok. that’s not an issue for me since I do not use it that much from HASS. I use Spotify through the built in support of forked-daapd mainly. Just sometimes when people come round and want to play something off Spotify that is not in my library I use librespot

This projects sounds really interesting, but I’m not sure it would work for my use-case. I’m looking for something that would allow me to control my iTunes library that’s on my PC (sadly, not a mac, so no API for it). I use smart playlists extensively, since I haven’t found any alternative that will let me use logic rules to sort my music, sync ratings, playcounts, and other metadata, and stream to my two Airport Express remote speakers.

Would this solution allow me to integrate Home Assistant with my iTunes located on my PC? Or, alternatively, could it be set up to point to an iTunes library on a NAS? I’m not familiar with Java or Python, so I’d like to get suggestions (or confirmation) from the community before I start messing with my setup.

This would be working if you can move your library to a NAS AND run forked-daapd instead of iTunes either on the NAS or some other linux computer (Raspberry Pi for example)

That’s amazing news! I’ll be able to test that out some time in the future, and see if I can figure it out. Thanks so much for letting me know. I’m assuming that I can run forked-daapd on the same rPi 3 that’s running HassIO, and that it can be installed using docker. Is this correct, or would I need to run it on a different linux machine?

same machine is fine.

Yeah you just have to think of forked-daapd as an iTunes server. It will manage your library and can output it to multiple Airplay speakers.

Unfortunately you need to use command line switches to control the outputs though and their individual volume because they are not yet in Hass (the point of this thread amongst other things).

Forked-Daapd now includes some json api so it should be much easier to control it from hass. The api is still not complete but working nicely already.

See discussion here: https://github.com/ejurgensen/forked-daapd/issues/462

1 Like

Hey man!

Can you give me some more details on this? I read the Github thread and it looks interesting, but it went a little over my head.

Sure. What exactly do you want to do? I would post my config but it’s a convoluted mess… so I’d rather post some specific sections…

I meant specifically regarding the API, whether there are now nicer ways of controlling which speakers were enabled, and their volume. Rather than through the CLI.

What I have configured are input_sliders and then the volume can be set and read via rest:

so I have a sensor:

sensor:
- platform: rest
    name: bedroom volume
    method: GET
    resource: http://forked-daapd-ip:3689/api/outputs/215949698466292
    value_template: '{{value_json.volume}}'
    scan_interval: 5

and a rest command to send the new volume when the input_number was changed.

rest_command:
  set_bedroom_volume:
    url: http://forked-daapd-ip:3689/api/outputs/215949698466292
    method: PUT
    payload: '{"volume" : {{ states.input_number.bedroom_volume.state|round }} }'

215949698466292is the speaker id.

you get those for example by curl http://forked-daapd-ip:3689/api/outputs

unfortunately there is no rest input_number component so you need automations as well to tie things together:

automation:
 - alias: 'Bedroom Volume Slider Change'
   trigger:
     platform: state
     entity_id: input_number.bedroom_volume
   action:
    - service: rest_command.set_bedroom_volume

 - alias: 'Bedroom Volume Change'
   trigger:
     platform: state
     entity_id: sensor.bedroom_volume
   action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.bedroom_volume
       value: '{{ states.sensor.bedroom_volume.state }}'

you can switch the speakers by defining a rest switch:

switch:
  - platform: rest
    name: Airplay Loop
    method: PUT
    resource: http://forked-daapd-ip:3689/api/outputs/215949697879210
    body_on: '{"selected": true}'
    body_off: '{"selected": false}'
    is_on_template: '{{value_json.selected}}'
    scan_interval: 5
2 Likes

You’re the man, dawg. I will digest this and report back!

I put together a video on my YouTube channel showing how I set things up. Should be useful as a reference for setting up both forked-daapd itself, as well as integration into Home Assistant. The video description has a link to a notes document that I use as a reference.

Credit to this thread for motivating me to set this up!

4 Likes

nice. your config is much neater than mine :wink: One suggestion may be to use the home-assistant universal media player on top.

1 Like