Bluesound and tts do not work

Hi,

New here so sorry if I put this question in the wrong place.

I am trying to use TTS together with Bluesound I get this error in my log:

2017-10-22 15:32:33 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1025, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/__init__.py", line 408, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/__init__.py", line 707, in play_media
    raise NotImplementedError()
NotImplementedError

It works fully with chromecast.

@Anders_Karlstrom , maybe you have an idea?

1 Like

Play_media is not implemented in the Bluesound component and it is required by TTS. I will look into it, hopefully I will be able to fix this before next release of HA

2 Likes

It seems that in order to play an url for Bluesound you should post to endpoint /playurl.
The post should be HTML Form URL Encoded: (application/x-www-form-urlencoded). Content shall be: Key: url, value: <url to play>

To test with curl:

curl -X POST -F 'url=<url to mp3>>' http://<bluesound ip address>/playurl

Note, just default port 80 shall be used for this.

actually:

the endpoint is: http://<bluesound IP address>:11000/Play
source: https://helpdesk.bluesound.com/discussions/viewtopic.php?t=2293

As a work-around I use pre recorded sound from internet:
Loading the endpoint into a shell_command works for me.

shell_command:
  playmp3: "curl -X POST -F 'url=http://www.orangefreesounds.com/wp-content/uploads/2017/10/Horror-creepy-whoosh-sound.mp3' http://<your IP>:11000/Play"

then you can use it in an automation

action:
    service: shell_command.playmp3

The only drawback is that if the speaker is playing something, it stops the current track, and plays the ā€˜newā€™ url. After this, the speaker does not revert back to playing the ā€˜oldā€™ track.

It seems that both urls is working. The one i proposed above is working with latest Bluesound software and is used by the Windows app, that is how I reveresed engineered that one. Note that the one I propsed are using port 80, not the api port 1100. Interesting enough there is a mini-web-server in any bluesound device at port 80. (Without any security at allā€¦)

Thanks for the easy integration example, I will try it. But still it would be nice with the built in functionality so that TTS could work. Maybe I will try to do it myself if not @Anders_Karlstrom is already at it . I also think that it then might be possible to revert back to the old source - at least if that was a preset.

I will look into this next week. It shouldnā€™t be a problem to fix this. The only problem with it is that it will be stopping what ever is playing and not continue with the played track after the TTS sound is played. To fix this I need ro implement a snapshot feature just as the sonos component. But that is more time consuming. I wont have time to implement that this year (I also promised to make a separate Python lib when Iā€™m implementing the next big feature, and since Iā€™m not a Python developer it takes som extra time)

2 Likes

Sorry about the delay, but I have now submitted a pull request with a fix for this. The PR also handles grouping of players and sleep timers.

When using TTS you have to clear the playlist of the device first. Bluesound will continue playing the playlist after the TTS sound if the playlist is not cleared. I didnā€™r find a workaround for this.

2 Likes

Awsome! @Anders_Karlstrom canā€™t wait to try it out!!

I will at some time try to mimic to snapshot/restore feature that the Sonos library supports, this will be a dealbreaker for TTS-use with Bluesound I think.

But this will take som time. First of I have promised to move a lot of the code in the component to a separate library, and since Iā€™m not a python developer this will take a lot of time for me. I will have to learn some python patterns before doing this (this is much easier in HA since I only needed to learn the pattern of HA to develop the component).
And after Iā€™ve learned python, I will have to develop the snapshot/restore feature which also will be time consuming, I have to figure out all parameters that will have to be stored.

But this feature will comeā€¦ some day :stuck_out_tongue:

2 Likes

Sorry to necro this topic but I didnā€™t want to create another topic for this snapshotting of bluesound. How far is the bluesound lib developed? Is taking a snapshot already possible like with Sonos?

1 Like

Another necro here :slight_smile:

Iā€™m considering investing in the bluesound/bluos as a replacement for LMS/Squeezebox/Squeezelite

@M4tthijs @Cezus @Anders_Karlstrom How is the Bluesound integration in HA today in 2021? Is TTS working? Any pain points? From a programmers perspective, how is it working with the bluesound APIs? Is it an open or closed system?

Hmmm I use the google home mini for tts. As far as I know the integration does not support pauze yet. I only set the source and volume with automations.

TTS is working, but Iā€™m not able to automatically restart the music after the TTS message ended. Would like to have a snapshot or scene functionality with the ā€œintegrationā€ā€¦

sorry for the late response. For me it still work well. It doesnā€™t support snapshot, but that is not something that is natively supported by Bluesound and would be needed to be part of the integration.
The bluesound API is ā€œclosedā€, as far as I havenā€™t found any documentation. I had to listen to network traffic when making the integration.
The biggest problem for me if I were to continue develop the integration is that the API-calls would need to be extracted to a separate lib, HA-team will most probably not accept any major code changes since I barely got it through code review last time. And I donā€™t have the time to do this, I donā€™t know python well enough and it would take to long for me right now.
This and the fact that I donā€™t have access to all products for ā€œreverse engineringā€ is a problem right now.

I really really would like to fix the integration to make it better, but when it still work I find it hard to justify me putting time into this.

I understand, the TTS isnā€™t a high priority for me anyways.

A month ago I submitted a bug report to about the bluesound integration. Itā€™s my first bugreport to HA, so Iā€™m not 100% sure how to get visibility on it. It hasnā€™t received any replies at all.

Maybe you could take a look at it? Iā€™ve poked around but donā€™t have a good enough understanding of the HA internals:

ItĀ“s a good thing you wrote here to let me know. I will add myself as codeowner of bluesound so that next time a bug is submitted I will get notified.

I have submitted a bugfix for this issue. Letā€™s hope it will be approved quickly

1 Like

Wow, thanks very much.

I see the reviewerā€™s comment that the integration should be refactored to use a 3rd party library.

Thatā€™s something I could help with if you want! It doesnā€™t seem so urgent though if the integration is working fine without large changes needed.

Yeah, it has been this way for a long time, but I have so many things I would like todo, I Will have to find some for this soon enough :slight_smile:

Anyway, the fix has been included in this release (2021.11) please let me now if it works or not. I have no reason to believe i doesnā€™t but I didnā€™t have the hardware to test different ports.

(You donā€™t need to use different hostnames if you donā€™t want to)