Custom component for bredbandskollen.se

Just wanted to share this techcode7821332.wordpress.com/2019/01/09/bredbandskollen-custom-component-for-homeassistant/

3 Likes

What version of CLI should you download for a Pi?

Go for https://frontend.bredbandskollen.se/download/bbk_cli_linux_amd64-1.0
Or https://frontend.bredbandskollen.se/download/bbk-cli_1.0.0_amd64.deb

Thank you.

I have this:

And when I check configuration I get:

Configuration invalid

Platform error sensor.bredbandskollen - Integration ‘bredbandskollen’ not found.

I have updated the guide so it’s upd to speed with new layout of custom_component

Doesn’t make any difference.

I first just created a new file and named in init and that didn’t work. Then I copied one from another custom component and deleted it’s contents. Still the same.

However…
If I change the name of the folder to “bredbandskollen” and the file name to sensor.py the config is valid. But I don’t get any new sensors.

I have now got to this stage:

Log Details (ERROR)

Logger: custom_components.bredbandskollen.sensor
Source: custom_components/bredbandskollen/sensor.py:68
Integration: bredbandskollen
First occurred: 10:52:37 AM (1 occurrences)
Last logged: 10:52:37 AM

127 /bin/sh: /local/bbk_cli_linux_amd64-1.0: not found

and

Log Details (ERROR)

Logger: homeassistant.components.sensor
Source: custom_components/bredbandskollen/sensor.py:46
Integration: Sensor (documentation, issues)
First occurred: 10:52:37 AM (1 occurrences)
Last logged: 10:52:37 AM

Error while setting up bredbandskollen platform for sensor

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 178, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File “/usr/local/lib/python3.7/asyncio/tasks.py”, line 442, in wait_for return fut.result() File “/config/custom_components/bredbandskollen/sensor.py”, line 68, in async_setup_platform await data.async_update() File “/config/custom_components/bredbandskollen/sensor.py”, line 46, in async_update self.data = data.split(’ ') AttributeError: ‘NoneType’ object has no attribute ‘split’

One is probably causing the other. But what is a good place for the file so that it can be found.
I tried the path both with “/local/” and “local/” none of them worked.

If you run /local/bbk_cli_linux_amd64-1.0 in commandline, does that work?

Seems hass is unable to find that file

I don’t know how to do that.

I’m guessing you run hassio, that is not the way I’m running my setup so I have a hard time helping with this

Ok. Thanks anyways

For anyone running hassio in docker and having a problem like this in the future.

The reason to why the bbk cli file can’t be found is that it’s compiled with gcc while hassio uses another compilation library called musl. This because hassio runs in Alpine Linux. To solve this you have to get the source code from the website (https://github.com/dotse/bbk) and compile it in a Linux installation that uses musl. I compiled it inside the homeassistant docker:

First ssh into the system running the docker. Then use:

docker exec -it docker_id /bin/sh
git clone https://github.com/dotse/bbk.git
cd bbk/src/cli
make

When the make command is done you’ll see the cli file inside the same folder and this should now be able to be found and ran.

I like that you are 5 days ahead of me. found both this post and the post about engine.h. but i can’t get this to work any way. it runs fine if i log in to the docker image. but not when using the custom component. did you change something else?

for reference i needed to create two additional files to get this to work

__init__.py

"""The Mobile App integration."""

manifest.json

{
  "domain": "bredbandskollen",
  "name": "Bredbandskollen",
  "documentation": "https://techcode7821332.wordpress.com/2019/01/09/bredbandskollen-custom-component-for-homeassistant/",
  "dependencies": [],
  "codeowners": [],
  "requirements": []
}

for references if some one else is looking for this, the issue was that i had put in path: "/config/deps/bbk_cli" and not path: /config/deps/bbk_cli

configuration.yaml

sensor:
  - platform: bredbandskollen
    path: /config/deps/bbk_cli

and yet another thing. when compiling the bbk_cli on alipine i got another format

alpine:

 128.049 129.144 10.2325 gbg2.bredbandskollen.se Bredband2 AB gbg20264cdb4

normally with downloaded binaries

10.34 127.858 129.215 gbg2029828e7

so i needed to modify the MAPPING in sensor.py

MAPPING = {
    'latency': 3,
    'download': 1,
    'upload': 2
}
1 Like

Wow. Sorry for the late reply, but great that you managed to fix it yourself!

I will update the posts as soon as I have some spare time

1 Like

i started working on a custom_component for hacs but failed and don’t have more time to put on this…

if someone wants to continue the code is here https://github.com/benganellison/bredbandskollen_custom_component_ha

update: it was a typo, think it works now

1 Like