Roon module for Home Assistant

Figured it out, service should be play_media, not media_play…haha

I am experiencing some issues with Room discovery. When my Zones leave and come back they don’t appear and I can no longer control them. i did update roon.py to latest version.

So when HASS starts, take a while for the dropdowns to get populated, but then everything works. After 30 minutes only my BlueSound and Appletv was in the list, and I couldn’t get my iMac sources to display. Same goes for the group.roon_players.

Not sure if it is HASS not getting the updates from Roon-api-proxy, or the api-proxy not seeing the correct lists in Roon. When I look at the Zone list in Roon all the zones are there.

Just wanted to say that I am looking at installing this today on my HASS hassio setup, many thanks for making this happen. Would also be interested to see if we can get it working with the Google Home/Assistant integration in HASS.

Mike C

It will work out of the box with Google Assistant, Siri (homebridge) and Amazon Alexa. Home assistant will take care of that for you

First Bump
When trying to install Node.js on Ubuntu 16.04 the run_extension.sh script could not find the “node” command
I symlinked the command to get by this

sudo ln -s /usr/bin/nodejs /usr/bin/node

Now I am getting a syntax error on the script

Node version is 4.26, I think I need 4.7?
edit: I see the API docs say you need 5.X or higher

roon-extension-api-proxy-master/app.js:47
        let curZones = msg.zones.reduce((p,e) => (p[e.zone_id] = e) && p, {});
        ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3

Yes, you need a newer version of node.

Reply to myself.
Upgraded to latest node.js from these instructions
https://nodejs.org/en/download/package-manager/

node.js version 8.9.4

and hey presto its now up and running, next step is HASS

Sweet!
This is now working on Hassio on a Raspberry Pi

Many thanks for this, will test and look to set up to work with Google Home

Mike C

Hi Marcel

One small problem I’m seeing is that the album playing info is not being updated when I change tracks or albums.
It stays with whatever it sees when HASS first starts.
My Roon core server is running on a different machine to HASS. Also endpoint is yet another machine.

Mike C

Will provide an update later today in which this is fixed, also fix for the issue reported by @Wouter_du_Toit

1 Like

new version is on GitHub

Thanks, upgraded!

Thanks @Marcel_van_der_Veldt it is has been working really well with the updated version…after 3 hours all my “rooms” are still in the list!

:rofl:

Upgraded
Media info now updating.

Track next and previous work, volume works but the pause button is not behaviour I was expecting.

Pause seems to be the same as turning off. ie the album art and track information disappears and play button greys out. You have to press the power button to resume play.
Is this the expected behaviour?

Also any chance you can post your configuration.yaml? Not sure I have the playlists widget right as per your notes on github.

What I would like to be able to do is to have Roon go to the Radio playlist (not internet radio) when I turn it on in HASS. This would link to Google Home (which currently only maps to Switches) so that I can say “Hey Google turn on Roon” and it goes straight into the radio play list and starts playing.

Mike C

1 Like

Software players (Roonbridge or client on pc/mac) do not have a power button/function so you can never turn them off. The Roon API returns these players as not supporting standby. Hardware players however (or players with additional source control) do have a power control so these can be turned off.

I was struggling a bit with this for a while because my family couldn’t understand why a zone was still listed as “powered on” in home assistant while it was not playing. So, I came up with a workaround by showing the players that do not support standby which are pauses/stopped as powered off.

Offcourse this is a personal preference for my own situation so I will append a configuration toggle for this behaviour in next update.

This is the configuration I have in place for the playlist widget:

input_number:
  roon_volume:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.01
input_select:
  roon_playlists:
    name: 'Playlist:'
    options:
      - Selecteer playlist
    initial: Selecteer playlist
    icon: mdi:spotify
  roon_players:
    name: 'Ruimte:'
    options:
      - Selecteer ruimte
    initial: Selecteer ruimte
    icon: mdi:speaker-wireless

Note that I used dutch phrases for the names, you can name those whatever you want.
In my views (groups section of hass), I’ve added this group:

roon_actions:
  name: Muziek spelers
  entities:
    - input_select.roon_players
    - input_select.roon_playlists
    - input_number.roon_volume

And this group is added to a view I created for all music related stuff:

muziek:
  name: Muziek
  view: yes
  entities:
    - group.roon_actions
    - group.roon_players

Now to make it even more complete, I’ve added each individual player to each “room view” in hass but that’s more personal taste I guess.

If you want to use hass to say “Turn on playlist Radio” or something like that with Google Assistant or Alexa, the most easy way (atm) is by using a script. Just add a script to your home assistant section;

script:
  playlist_radio:
    alias: "Playlist Radio"
    sequence:
      - service: media_player.play_media
        entity_id: media_player.kitchen
        data:
          media_content_id: "My playlist name in Roon"
          media_content_type: "playlist"

I don’t know about Google Assistant but Alexa picks up these scripts as available entities so you can just control them like your lights.

Offcourse a real integration between Google and/or Alexa would be even better but for now you can already do a lot with using hass in between.

Hi Marcel, a toggle should do it.
I have both Alexa and Google Home here so will play with these and report back

Mike C

Hi Marcel

Just another small item.

The Playlist / Radio stations list in the Bonus widget is not updating when changes are made in Roon.
Again not sure if this is expected behaviour. When I reload the HASS core it updates, not a big issue as I don’t think I will change these too much once set up.

The Room selections work as expected ie when a Roon endpoint is removed or added it updates (this is really nice by the way).

A more serious issue is I’m getting crashes in the NodeJS server occasionally

Here is output from the console

[mike@ThinkPad-T410 roon-extension-api-proxy-master]# node .
Listening on port: 3006
/home/mike/Downloads/roon-extension-api-proxy-master/node_modules/node-roon-api/moo.js:187
let cb = this.requests[msg.request_id].cb;
                                       ^

TypeError: Cannot read property 'cb' of undefined
at Moo.handle_response (/home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/node-roon-api/moo.js:187:44)
at Transport.transport.onmessage.msg [as onmessage] (/home/mike/Downloads/roon-extension-
api-proxy-master/node_modules/node-roon-api/lib.js:411:27)
at WebSocket.Transport.ws.onmessage (/home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/node-roon-api/transport-websocket.js:30:14)
at WebSocket.onMessage (/home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/ws/lib/WebSocket.js:442:14)
at emitTwo (events.js:126:13)
at WebSocket.emit (events.js:214:7)
at Receiver.onbinary (/home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/ws/lib/WebSocket.js:848:10)
at /home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/ws/lib/Receiver.js:628:18
at Receiver.applyExtensions (/home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/ws/lib/Receiver.js:371:5)
at /home/mike/Downloads/roon-extension-api-proxy-
master/node_modules/ws/lib/Receiver.js:604:14

Mike C

Hi Mike, the playlists/radios are updated every 5 minutes, the players are updated instantly indeed as changes are actively pushed by the web sockets.
The crash appears to be happening in the API library itself but I’ll see if I can reproduce. Make sure that the node module (or docker container) is auto restarted when it happens for the time being.

Thanks Marcel

I have created the following script that restarts the service for anyone else that needs it (Ubuntu 16.04).

#!/bin/bash
# NodeJS respawn script, replace path for node with location where you downloaded the code

until node /home/mike/Downloads/roon-extension-api-proxy-master; do
    date +"%r"
    echo "Server 'nodejs' crashed with exit code $?.  Respawning.." >&2
sleep 1
done

exit 0

I had a load of crashes (exit code1) when it was just sitting there and Roon was not playing or active.

Also I see this problem is also here

https://community.roonlabs.com/t/roon-extension-manager-v0-5-1-now-on-github/26632/94

Looks like an API Issue as you say.

On the update, every 5 Mins is that what Roon updating or you are polling every 5Mins?

Otherwise, this works great and I love being able to select a Roon endpoint and a playlist or radio from HASS and it just plays. I’m finally going to look at the G-home connections now.

Cheers
Mike C

2 Likes

@Oldbloke I am polling every 5 minutes for the playlists and web radios. Player updates are received instantly by the web sockets connection.