HifiBerry OS – Media Player integration

I’m considering buying Hifiberry for an audio player, so your integration looks very promising.
Are you planning to add it to the HA repo?
That would be awesome!

It’s on the standard HACS repo now. I would look to add to HA but it requires use of PyPi:

Interfacing with devices#

One Home Assistant rule is that the integration should never interface directly with devices. Instead, it should interact with a third-party Python 3 library. This way, Home Assistant can share code with the Python community and keep the project maintainable.

Once you have your Python library ready and published to PyPI, add it to the manifest. It will now be time to implement the Entity base class that is provided by the integration that you are creating a platform for.

Find your integration at the entity index to see what methods and properties are available to implement.

This is a bit beyond my capability to be honest, I’d be happy for someone to help implement this with me.

@frenck Is this really a dependency for this small integration?

I just setup an Hifiberry and google for an existing integration (which brought me here)

I decided to give this integration a push towards making it official and pushed minutes ago a python library: https://github.com/dgomes/pyhifiberry

Tell me if you need anything extra, or how I can support your PR :wink:

5 Likes

willholdoway would you mind if I fork your PR?

1 Like

@willholdoway it would be great if you guys put this together :slight_smile: thanks @dgomes

Sorry @dgomes been a crazy month, I meant to say please go ahead and I’m keen to work on this with you! I’ve been meaning to incorporate your pypi package but I have not found the time to sit down and give it a proper crack as of yet. What are the next steps for you?

Yes let’s get this moving, would love it to be official as HifiBerry is such a cost-effective and versatile option!

Hi @willholdoway, myself I haven’t been able to put some time into this, but still in my ToDo list :slight_smile:

I think we should start by refactoring your existing PR to use the python library I published https://github.com/dgomes/pyhifiberry

If you find something missing I will update the library accordingly and will also fix anything :sweat_smile:

1 Like

I googled a bit and came here. Thanks for contributing, guys. I’ll hopefully be able to use your integration for controlling media with a dedicated screen.

1 Like

I’ve create a PR which uses the supporting library and create a config_flow

1 Like

Thanks @dgomes and @willholdoway! Just installed this to see if I can figure out how to get HiFiBerry OS to control multiple zones in my house.

Thanks this works great, installed via HACs, and was able to use the playing status to turn on my amp!

1 Like

Since the latest update I’m getting this error message constantly in the Home Assistant log. Any idea what may be causing it? Media service control of HifiBerry’s has been flaky, and sometimes takes a couple of attempts to trigger an automation by light switch for example.

ERROR (MainThread) [pyhifiberry.audiocontrol2] Audiocontrol2Exception Could not connect to Hifiberry host. caused by: [Errno 104] Connection reset by peer

Hifiberry is an awesome OS : On Raspberry 3 it supports Airplay 2, Squeezelite , Spotify connect , MPD , UPNP and others ! It works out of box without tweaking. On Rpi4 I think bluetooth input is avaible too.
I put my secondary Pi-Hole on it thanks to the preinstalled docker (and also an LMS server).

Thanks to your integration I put my amplifier to the right source when something is playing on my Hifiberry.
Very happy of the result :grinning_face_with_smiling_eyes:

Hello, I am starting to use hifiberry os, because it seems to me that is a good solution out of the box.
The installation went smooth, everything is working fine, but the integration with home assistant it becomes unavailable every 20 seconds or so. In the log appears this error:

Logger: pyhifiberry.audiocontrol2
Source: /usr/local/lib/python3.9/site-packages/pyhifiberry/audiocontrol2.py:29
First occurred: 13 de fevereiro de 2022 00:00:00 (1508 occurrences)
Last logged: 10:16:01

Audiocontrol2Exception Timeout connecting to Hifiberry host. caused by:
Audiocontrol2Exception Could not connect to Hifiberry host. caused by: [Errno 104] Connection reset by peer
Audiocontrol2Exception Couldn't request http://192.168.1.114:81/api/volume, status: 500 caused by: None
Audiocontrol2Exception Couldn't request http://192.168.1.114:81/api/system/poweroff, status: 403 caused by: None
Audiocontrol2Exception Could not connect to Hifiberry host. caused by: Response payload is not completed

When I try to increase or decrease the volume appears an error, but it works. In the log appears this error:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/hifiberry/media_player.py:225
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 13 de fevereiro de 2022 19:16:03 (6 occurrences)
Last logged: 10:27:10

[547706166192] 'dict' object has no attribute 'decoder'
[547711191120] 'dict' object has no attribute 'decoder'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyhifiberry/audiocontrol2.py", line 57, in _request
    raise Audiocontrol2Exception(f"Couldn't request {url}, status: {res.status}")
pyhifiberry.audiocontrol2.Audiocontrol2Exception: Couldn't request http://192.168.1.114:81/api/volume, status: 500

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 190, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/config/custom_components/hifiberry/media_player.py", line 225, in async_mute_volume
    await self._audiocontrol2.volume(int(self._muted_volume * 100))
  File "/usr/local/lib/python3.9/site-packages/pyhifiberry/audiocontrol2.py", line 108, in volume
    r = await self._request("POST", API_VOLUME, json={"percent": str(vol)})
  File "/usr/local/lib/python3.9/site-packages/pyhifiberry/audiocontrol2.py", line 65, in _request
    except json.decoder.JSONDecodeError as err:
AttributeError: 'dict' object has no attribute 'decoder'

Can anyone help me?

Thanks in advance.
Hugo Ferreira

Failed to connect to either of my hifiberry os devices when I try to configure in Integration, newly detected integrations. I have been using the integration for a while with success, this started after a recent update of the addon. The hifberry os is the latest. Tried to revert to olter hifiberry os, same issue. I can connect to the device via bowser API command.

Any ideas what I can check, something changed?

What fixed it for me is:
Log into the hifiberry:

ssh [email protected]

edit /etc/audiocontrol2.conf like so:

nano /etc/audiocontrol2.conf

And change the config bit under [webserver] to reflect this:

[webserver]
enable=yes
port=81
socketio_enabled=True

I hope this helps

1 Like

I was missing the socketio_enabled=True

Was this something that changed, I had it running earlier? I see it is documented but I had a hard time discovering though as I had it up and running before, thanks for sharing @makzdot

Marcus

1 Like

If you click on the integration there’s a link to the documentation…That;s where I found it.