INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Apparently Functional Integration with HomeAssistant  (Read 2429 times)

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Apparently Functional Integration with HomeAssistant
« on: January 07, 2024, 05:26:02 pm »

I've pushed an apparently functional integration to https://github.com/3ll3d00d/jriver_homeassistant which can be installed as a custom repository via HACS

No docs as yet and no formal release but available to try it out if you want to play with it

it provides 3 platforms for a given MC instance

* media player (https://www.home-assistant.io/integrations/media_player/), supports nearly all functions (sound mode & join/unjoin not supported) and exposes a few additional services (https://github.com/3ll3d00d/jriver_homeassistant/blob/main/custom_components/jriver/services.yaml), browsing (as per panel) should work.
* remote (https://www.home-assistant.io/integrations/remote/), send command basically maps to MCWS/v1/Control/Key and supports sending any keypress as well as the special commands
* sensor (https://www.home-assistant.io/integrations/sensor/), currently just exposes the currently active zone

for media player, there are 2 modes, one in which it exposes each zone as a separate device and another where it just exposes a single device (i.e. assumes you either have a single zone or use zoneswitch)

for browsing, there's no MCWS api to get the browse view config so you have to enter it in manually to specify the shape of the tree (i.e. names, tags) otherwise no way to work out what the content is without pulling potentially large quantities of data back from MC. The config looks like the attached pic, it's currently a comma separated list of names (the tree part of the config) pipe separated to another comma separated list (of field names, aka the categories that are shown under that browse path).

probably there's stuff that will change in this before I officially drop a release, will see how it goes.

Submitting a PR to HA itself looks pretty onerous so not sure that will happen, will also see how that goes

See for me, I have multiple JRiver clients and it seemed impractical to juggle them and their IPs
yes it's not ideal atm, the vast majority of people are neither willing nor capable of writing their own app as a layer on top of their MC setup just to get a bit of control over it in HA though :)
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72438
  • Where did I put my teeth?
Re: Apparently Functional Integration with HomeAssistant
« Reply #1 on: January 08, 2024, 01:28:47 am »

Thanks, Matt.
Logged

flac.rules

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1268
Re: Apparently Functional Integration with HomeAssistant
« Reply #2 on: January 08, 2024, 03:59:26 am »

Nice, looking forward to testing, getting HA control over MC would be great.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #3 on: January 08, 2024, 05:05:59 am »

Fwiw if I could ask for one thing to improve this, it would be https://yabb.jriver.com/interact/index.php/topic,137769.0.html as that's a really quite ugly bit of manual configuration, would be great to be able to avoid that
Logged

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494
Re: Apparently Functional Integration with HomeAssistant
« Reply #4 on: January 08, 2024, 07:58:57 am »

thank you so much @mattkhan!

will test it when I get home!

Z
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13870
Re: Apparently Functional Integration with HomeAssistant
« Reply #5 on: January 08, 2024, 09:16:21 am »

related HA github issue -> https://github.com/StevenLooman/home-assistant-dlna-dmr/issues/13#issuecomment-752015900
That's for precision zone sync. It should not be there if precision zone sync feature is off.
At first glance looks like a bug to me.
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #6 on: January 08, 2024, 10:29:23 am »

I've pushed an apparently functional integration to https://github.com/3ll3d00d/jriver_homeassistant which can be installed as a custom repository via HACS

I like the start! Took me a bit to get the view setup for browsing, but after I re-read the description a few times, I got it corrected. When I play something from the browse, it only works when I play a single file (not whatever level is above that). Then If I browse somewhere else and click the play button on a non-file, my MC playing now just duplicates whatever was already in it.

Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #7 on: January 08, 2024, 11:03:46 am »

I like the start! Took me a bit to get the view setup for browsing, but after I re-read the description a few times, I got it corrected. When I play something from the browse, it only works when I play a single file (not whatever level is above that). Then If I browse somewhere else and click the play button on a non-file, my MC playing now just duplicates whatever was already in it.


Thanks for testing! I will write proper docs soon and split the thread, until then... I can play a folder for sure, anything custom/unusual about your browse tree or it's just some standard setup?
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13870
Re: Apparently Functional Integration with HomeAssistant
« Reply #8 on: January 08, 2024, 11:57:35 am »

That's for precision zone sync. It should not be there if precision zone sync feature is off.
At first glance looks like a bug to me.
Figured that out. It's interesting that HA cares about the extra parameters where other controllers seem to ignore them.
So at least the play/stop works now. Not sure why pause isn't exposed. Looking into that one.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #9 on: January 08, 2024, 12:23:53 pm »

I like the start! Took me a bit to get the view setup for browsing, but after I re-read the description a few times, I got it corrected. When I play something from the browse, it only works when I play a single file (not whatever level is above that). Then If I browse somewhere else and click the play button on a non-file, my MC playing now just duplicates whatever was already in it.
I retested

say I have one of the standard browse like Audio > Album  then playing a specific album works fine, browse to another album then it replaces playing now with that new album but playing a single entry (e.g. a single track in the album) only plays the 1st item even if I pick the nth so there must be some bug there

If I now go and pick another album to play, it plays as expected

I cannot reproduce this "append a track to playing now" behaviour though, regardless of what I pick, which is what I'd expect because it calls Playback/ClearPlaylist before it plays anything new

can you look at the MC logs and see what MCWS calls are coming in? grep for MCWS should do it

i.e. lines that have this sort of format

Code: [Select]
0000025: 15484: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/Info?Fields=Aspect%20Ratio%3BHDR%20Format%3BPlayback%20Info&Zone=10002&ZoneType=ID
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #10 on: January 08, 2024, 12:49:31 pm »

I retested

say I have one of the standard browse like Audio > Album  then playing a specific album works fine, browse to another album then it replaces playing now with that new album but playing a single entry (e.g. a single track in the album) only plays the 1st item even if I pick the nth so there must be some bug there

If I now go and pick another album to play, it plays as expected

I cannot reproduce this "append a track to playing now" behaviour though, regardless of what I pick, which is what I'd expect because it calls Playback/ClearPlaylist before it plays anything new

can you look at the MC logs and see what MCWS calls are coming in? grep for MCWS should do it

i.e. lines that have this sort of format

Code: [Select]
0000025: 15484: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/Info?Fields=Aspect%20Ratio%3BHDR%20Format%3BPlayback%20Info&Zone=10002&ZoneType=ID

I missed that you had split the thread so I didn't see this.

The hierarchy that I was messing with is for my live recordings, which means it's set like this: Audio,Live|Album Artist (auto),Series/ Tour, Season/ Show Date, Source, Type

Perhaps I'd be better off testing with more standard views, but that's what I picked off the bat. If I navigate to an Artist, then a Tour and hit play on a Show Date, I see something like this:
Code: [Select]
0004519: 8224: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/PlayByFilename?Filenames=N%7C2857%7CAudio+%3E+Live+%3E+Alexi+Murdoch+%3E+Unassigned+%3E+2011-03-24+%3E+Unassigned+%3E+flac16

However, that's not the filename, that's just how I have the views broken up.

If I play the individual file, it plays via the key, which then works:

Code: [Select]
0154156: 7824: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.2.102: GET: http://192.168.3.202:52199/MCWS/v1/Playback/PlayByKey?Key=446186
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #11 on: January 08, 2024, 12:52:53 pm »


I cannot reproduce this "append a track to playing now" behaviour though, regardless of what I pick, which is what I'd expect because it calls Playback/ClearPlaylist before it plays anything new


I think this is happening because of the way that the filename is being passed back because MC then tries to find files that aren't named that way:

Code: [Select]
0004945: 8224: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.2.102: GET: http://192.168.3.202:52199/MCWS/v1/Playback/PlayByFilename?Filenames=N%7C2857%7CAudio+%3E+Live+%3E+Alexi+Murdoch+%3E+Unassigned+%3E+2011-03-24+%3E+Unassigned+%3E+flac16
0004945: 8224: Sharing Plugins: JRWebService::Process: Start
0004945: 8224: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/PlayByFilename?Filenames=N%7C2857%7CAudio+%3E+Live+%3E+Alexi+Murdoch+%3E+Unassigned+%3E+2011-03-24+%3E+Unassigned+%3E+flac16
0004945: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer: 0x19e9cfe7130
0004945: 8224: Database: CMediaDatabase::AddFile: Calling JRAnalyzer::Open
0004945: 8224: Import: JRAnalyzer::Open: Start
0004945: 8224: Import: JRAnalyzer::AddFile: Start
0004945: 8224: Import: JRAnalyzer::AddFile: Filename: N
0004945: 8224: Import: JRAnalyzer::AddFile: Start
0004945: 8224: Import: JRAnalyzer::AddFile: Filename: N
0004945: 8224: Import: JRAnalyzer::AddFileData: Start
0004946: 8224: Import: JRAnalyzer::AddFileData: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::Open: Finish (0 ms)
0004946: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer::Open returned
0004946: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer: 0x19e9cfe65d0
0004946: 8224: Database: CMediaDatabase::AddFile: Calling JRAnalyzer::Open
0004946: 8224: Import: JRAnalyzer::Open: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Filename: 2857
0004946: 8224: Import: JRAnalyzer::AddFile: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Filename: 2857
0004946: 8224: Import: JRAnalyzer::AddFileData: Start
0004946: 8224: Import: JRAnalyzer::AddFileData: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::Open: Finish (0 ms)
0004946: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer::Open returned
0004946: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer: 0x19e9cfe6e90
0004946: 8224: Database: CMediaDatabase::AddFile: Calling JRAnalyzer::Open
0004946: 8224: Import: JRAnalyzer::Open: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Filename: Audio > Live > Alexi Murdoch > Unassigned > 2011-03-24 > Unassigned > flac16
0004946: 8224: Import: JRAnalyzer::AddFile: Start
0004946: 8224: Import: JRAnalyzer::AddFile: Filename: Audio > Live > Alexi Murdoch > Unassigned > 2011-03-24 > Unassigned > flac16
0004946: 8224: Import: JRAnalyzer::AddFileData: Start
0004946: 8224: Import: JRAnalyzer::AddFileData: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::AddFile: Finish (0 ms)
0004946: 8224: Import: JRAnalyzer::Open: Finish (0 ms)
0004946: 8224: Database: CMediaDatabase::AddFile: JRAnalyzer::Open returned
0004946: 8224: Sharing Plugins: JRWebService::Process: Finish (0 ms)
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #12 on: January 08, 2024, 02:20:33 pm »

interesting, it means you're hitting a path that I wasn't expecting to be hit but is present in other media_player integrations in the HA codebase :)

it means media_type == 'file' but I haven't managed to hit that in my browse tree so am wondering how you get there, will have to play around some more to see where it comes from

Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #13 on: January 08, 2024, 02:26:19 pm »

say I have one of the standard browse like Audio > Album  then playing a specific album works fine, browse to another album then it replaces playing now with that new album but playing a single entry (e.g. a single track in the album) only plays the 1st item even if I pick the nth so there must be some bug there
was wrong about this, it is playing the right track
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #14 on: January 08, 2024, 02:42:35 pm »

on the other hand, I did recreate that "it duplicated playing now" behaviour and I think it's a bug in MC, posted separately in https://yabb.jriver.com/interact/index.php/topic,137793.0.html
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #15 on: January 08, 2024, 03:03:23 pm »

both those issues should be fixed now (update the repo in HACS to pull it down)
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #16 on: January 08, 2024, 03:10:02 pm »

interesting, it means you're hitting a path that I wasn't expecting to be hit but is present in other media_player integrations in the HA codebase :)

it means media_type == 'file' but I haven't managed to hit that in my browse tree so am wondering how you get there, will have to play around some more to see where it comes from

I noticed when I play via Panel at this level, it still sends keys back into MCWS. I tried to reset the logs and make this straightforward:

Code: [Select]
0042356: 5444: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Browse/Files?Version=2&Token=SS92c31A&ID=1591&Action=Serialize
0042368: 9512: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.6.225: GET: http://192.168.3.202:52199/MCWS/v1/Browse/Children?Version=2&Token=SS92c31A&ID=1601
0042368: 7788: Database: CSearchFilesHelper::GetResults: Search: [Album Artist (auto)]=[Alexi Murdoch] [Filename (path)]="verified" -[Filename (path)]="00_not_in_db_yet"; Elapsed ms: 17.460
0042368: 9512: Sharing Plugins: JRWebService::Process: Start
0042368: 9512: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Browse/Children?Version=2&Token=SS92c31A&ID=1601
0042369: 7788: Sharing Plugins: JRWebService::Process: Finish (23 ms)

...

Then lots of other artists, I assume when it "draws" the page

Then some more navigation as I pull up the actual concert, which is stored in the Season tag (2011-03-24):
...

0049950: 9512: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.6.225: GET: http://192.168.3.202:52199/MCWS/v1/Browse/Files?Version=2&Token=SS92c31A&ID=2856&Action=Serialize
0049951: 9512: Sharing Plugins: JRWebService::Process: Start
0049951: 9512: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Browse/Files?Version=2&Token=SS92c31A&ID=2856&Action=Serialize
0049958: 9512: Database: CSearchFilesHelper::GetResults: Search: [Source]=[] [Season]=[2011/-03/-24] [Series]=[] [Album Artist (auto)]=[Alexi Murdoch] [Filename (path)]="verified" -[Filename (path)]="00_not_in_db_yet"; Elapsed ms: 6.412

...

0052193: 7788: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.6.225: GET: http://192.168.3.202:52199/MCWS/v1/Playback/SetPlaylist?Zone=10512&Playlist=2%3B15%3B0%3B446187%3B446186%3B446189%3B446195%3B446198%3B446192%3B446185%3B446191%3B446193%3B446199%3B446196%3B446188%3B446190%3B446197%3B446194&Token=SS92c31A
0052194: 7788: Sharing Plugins: JRWebService::Process: Start
0052194: 7788: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/SetPlaylist?Zone=10512&Playlist=2%3B15%3B0%3B446187%3B446186%3B446189%3B446195%3B446198%3B446192%3B446185%3B446191%3B446193%3B446199%3B446196%3B446188%3B446190%3B446197%3B446194&Token=SS92c31A
0052195: 7788: Sharing Plugins: JRWebService::Process: Finish (1 ms)
0052195: 7788: Sharing Plugins: VHTTPMessage::Write: Wrote 83 bytes
0052195: 9512: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 192.168.6.225: GET: http://192.168.3.202:52199/MCWS/v1/Playback/PlayByIndex?Zone=10512&Index=0&Token=SS92c31A
0052196: 9512: Sharing Plugins: JRWebService::Process: Start
0052196: 9512: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Playback/PlayByIndex?Zone=10512&Index=0&Token=SS92c31A
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #17 on: January 08, 2024, 03:23:36 pm »

both those issues should be fixed now (update the repo in HACS to pull it down)

Wow, thanks! Just updated and click Play at a higher level is pushing the content into my zone correctly now.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #18 on: January 08, 2024, 03:31:08 pm »

interesting, thanks.

They seem equivalent in the sense that both operations require 2 calls

technically my approach has a race condition (I make 2 calls to play, once to clear the playlist and then to to Browse/File to play it) so the panel implementation is superior in that regard, on the other hand the panel impl could lead to a massive URL which provokes a 414 response.

I'd say both problems are theoretical rather than practical as I assume people don't attempt to play truly gigantic playlists and the probability of someone adding content to playing now at just the right time inbetween the two calls I make seems vanishingly small :)
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #19 on: January 08, 2024, 03:33:14 pm »

so far I haven't implemented use of an access key, does anyone need this? i.e. have HA connect via an access key instead of directly to host/ip?
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13870
Re: Apparently Functional Integration with HomeAssistant
« Reply #20 on: January 08, 2024, 04:15:33 pm »

Figured that out. It's interesting that HA cares about the extra parameters where other controllers seem to ignore them.
So at least the play/stop works now. Not sure why pause isn't exposed. Looking into that one.
Well that led to more cool DLNA stuff. The GetCurrentTransportActions wasn't adapting to playback state (and wasn't including pause). Added that too (in MC32).
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #21 on: January 08, 2024, 04:28:22 pm »

 
Well that led to more cool DLNA stuff. The GetCurrentTransportActions wasn't adapting to playback state (and wasn't including pause). Added that too (in MC32).

that's great, thanks
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #22 on: January 08, 2024, 04:28:49 pm »

Logged

eve

  • Citizen of the Universe
  • *****
  • Posts: 689
Re: Apparently Functional Integration with HomeAssistant
« Reply #23 on: January 08, 2024, 07:00:21 pm »


Man, this is a great addition. I wish this was around 8 months ago.


so far I haven't implemented use of an access key, does anyone need this? i.e. have HA connect via an access key instead of directly to host/ip?
So when I started using JRiver (we're talking 15 years back now almost... jeeze) I liked the access key. I didn't have like total control over my network topology and I knew much less about this stuff, an access key made sense (man it was mindblowing like loading my library on another computer and streaming it).
It might be a worthwhile inclusion for the less technically inclined?
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Apparently Functional Integration with HomeAssistant
« Reply #24 on: January 08, 2024, 07:33:48 pm »

Man, this is a great addition. I wish this was around 8 months ago.

So when I started using JRiver (we're talking 15 years back now almost... jeeze) I liked the access key. I didn't have like total control over my network topology and I knew much less about this stuff, an access key made sense (man it was mindblowing like loading my library on another computer and streaming it).
It might be a worthwhile inclusion for the less technically inclined?

Agreed. It's something that will need to be there *at some point* for more users. If you look at the Venn digram overlap between JRiver and HA users, I'm willing to bet we all have static IPs.
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72438
  • Where did I put my teeth?
Re: Apparently Functional Integration with HomeAssistant
« Reply #25 on: January 09, 2024, 02:01:20 am »

If you look at the Venn digram overlap between JRiver and HA users, I'm willing to bet we all have static IPs.
I use DHCP on several networks, without problems.  Routers re-assign the same address to the same device automatically.

I also use the Access Key exclusively, without problems.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #26 on: January 09, 2024, 03:30:22 am »

Made a note to implement that https://github.com/3ll3d00d/jriver_homeassistant/issues/2

If anyone has any other ideas of things to add then feel free to log it over there

Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4226
Re: Apparently Functional Integration with HomeAssistant
« Reply #27 on: January 10, 2024, 02:36:26 am »

started a thread on the 3rd party board for this & completed the docs on the readme -> https://yabb.jriver.com/interact/index.php/topic,137808.0.html

probably can lock this thread now and continue over there
Logged
Pages: [1]   Go Up