Freebox device tracker

Hello everyone!

I’m currently developing a device tracker platform for the Freebox, the server/router of the french FAI Free, along the lines of PR #10702 (sorry, cannot post more than two links). I have a working version based on freepybox, but I’m waiting for some pull requests to be merged in this project. In the meantime, I have a few questions:

  1. The Freebox requires a manual intervention from the user to authorize applications, pretty much like the Hue bridge does: the first time an application requests access to the server, the user must authorize it directly on the device. What would be the correct way to handle this? Do I need to make a custom component so that the user can configure the access from the home page, as is done for Hue for instance, or is it acceptable to simply give instructions in the documentation (for starters)?

  2. I have made a second version that automatically setup the device tracker through discovery. Is it something desirable? Device tracking can be seen as a bit intrusive, is it a good idea to start doing it without user intervention? If not, what would be the correct approach to notify the user that we discovered a Freebox device, along with the host and port to use in her configuration file if she wishes to set it up?

  3. Just to be sure I understand correctly how to implement a device tracker: get_scanner can be used to return a “simple” scanner that provides one method to get the list of current devices, and one method to get the name of a specific device. These methods are called automatically by another service that takes care of honoring interval_seconds. However, this approach cannot handle discovery. On the other hand, it is also possible to implement setup_scanner, which is passed either the config coming from the configuration.yaml (explicit configuration) or the discovery info (automatic configuration). When implementing setup_scanner, we are responsible for scheduling the refresh of devices, taking into account interval_seconds and using the see callback passed as an argument. Is all that correct? Do I need to handle consider_home, track, etc., or are they handled by the see callback?

If anyone is interested, I have pushed my WIP on my HASS fork. Perhaps it would be best to create a pull request to initiate discussion rather than asking questions here? I’m not sure what is the appropriate workflow :slight_smile:

Cheers

4 Likes

Well I’ve created a pull request here!

Hello , I m looking for this device tracker intgration since a while.
Do we have an idea when the freebox component will be available in a standard release.
or is there a procedure to implement it manually.
thks

Before this integration gets merged in an official release, we need at least a new release of the library I used for communicating with the Freebox. There is an open issue on the lib repo for that, but we still haven’t heard from the maintainer : https://github.com/fstercq/freepybox/issues/4.

Once this is done, the component could be integrated but the code will have to be reviewed by the home-assistant devs first. We have discussed about improving the configuration flow, I’m currently working on it but I think I will propose to do that in a second time, as the component is usable as it is.

If you want to beta test the component, you can checkout the pull request in your local installation if you are already using a git clone. If you have a standard installation, it would probably be possible to retrieve the component from the pull request and add it as a custom component. We can discuss that on the Pull Request thread if you want (https://github.com/home-assistant/home-assistant/pull/12727).

Hi @stilllman,

It’s good to read you are working on a freebox device tracker. I wrote a similar component (that I still use daily) a few months ago but I did not get the time to improve it as requested.

Do you have new information about your component ? Did you choose to keep the discovery function ?

Hey @2t0m!

I saw your component when I started looking for a device tracker for the Freebox, but when I saw that your PR had been closed I decided to write another one. Your implementation was a great help to know where to start!

My PR is currently on hold because it depends on some modifications I submitted on Freepybox that have been merged but not released yet. Unfortunately, the maintainer doesn’t seem very responsive. I’m starting to consider a hard fork of the library, not only to be able to release new versions, but also to possibly transition to an async implementation (perhaps using aiohttp). I’m not sure how to proceed to avoid being disrespectful to the original maintainter fstercq though.

The current PR is composed of two commits, one that only adds the device tracker component and a second one that adds the automatic discovery. It is usable but not very user-friendly because there is no indication that you need to authorize the application on the Freebox hardware (there is only a message displayed on the log). There is a new feature in Home Assistant called config flow that would be perfect for this use case, but it requires quite a bit of additional work, and I would like to avoid bloating the PR with too much code.

Are you satisfied with your implementation of the component? Did you notice any problems with the Freebox API that I should be aware of? If you want to beta test my component, or if you want to propose improvements, any feedback or contribution would be much welcomed :slight_smile:

The config flow feature (I didn’t know about) seems to be a very good choice. I totally agree the manual authorization process is not user-friendly at all…

I’m satisfied with my component and I don’t have any problem with it. Be sure I will try yours ASAP.

I hope you will soon get an answer from fstercq.

Just so you know, the PR has been merged, so it should be available in the next release (0.72)!

That’s good news !

Yes good news. Does it work with all freebox?

Well I’ve only tested it with the Freebox 4k, but the API is the same for all Freebox’es so it should work with others as well. And if it does not work, bug reports are much welcomed!

Seems Freebox Crystal is not supported.
http://mafreebox.freebox.fr/api_version return

"uid":"REMOVED","device_name":"Freebox ADSL","api_version":null,"api_base_url":null,"device_type":"Freebox5,1"}```

@oncleben31 Thanks for the feedback. According to https://dev.freebox.fr/sdk/server.html , the API is only available with FreeboxOS, which is not available on the Crystal :/. I thought they had deployed it on older devices, but it seems not, only the Revolution and the Mini 4k have it. I should update the documentation of the hass platform with this info.

1 Like

Hi,

I would like to track only some devices.
So I have enabled the freebox tracker in the configuration.yaml like this :

device_tracker:
  - platform: freebox
    host: mafreebox.free.fr
    port: 80
    new_device_defaults:
      track_new_devices: False
      hide_if_away: True

But when I do that the tracking is not working anymore. The devices are still listed and refreshed in known_devices.yaml but the status icons are not refreshed anymore on the homepage.

Any idea of the origin of the problem ?

Hey @schmurtz,

Have you specified in the known_devices.yaml which devices you want to track by setting track: true?

Hi There,

Trying to get this work with my hassbian install. Basically it works, but it keeps asking on my freebox revolution if i’m OK to associate the hassbian application every 30 seconds…

So i decided to fix the freebox platform in my config but now i have as log : get_session_token failed
I checked the host and port, everything seems to be correct.
When i fix the values in the config, there’s no popup at all on the freebox.

Could you help ?

Hey @SNoof85,

It looks like the storage of the authentication token is not done correctly. It should be saved in a file called “freebox.conf” inside the home Assistant configuration directory; could you check if there is such a file there, and if there isn’t, check if Home Assistant has write access to this directory?

@stilllman mais oui !
Thanks a lot, the file was here and i probably done something wrong with the rights on the configuration folder.I’ve deleted it and now it asked again on the freebox with the discovery and it asked only 1 time :slight_smile:
Thanks again for this quick and good answer, and also for the work done on this project.

Edit : oops, i spoke a bit fast, i see few seconds later my answer that the freebox keeps asking for auth… and in the web interface of the router i see many auth failures (because i don’t confirm the access each time…)

Edit2 : in the freebox.conf file i have :

{"app_version": "0.65", "track_id": 118, "app_id": "hass", "app_token": "E9Gkc77mKvxDsN1myLWaoM3b6A97PnQvWb4ZvZ7nzygf/bycodS+ARDmndCWwcrl", "device_name": "hassbian", "app_name": "Home Assistant"}

@SNoof85 The content of the file seems correct, so the problem probably lies elsewhere. The library used to connect to the Freebox lacks some logging to help identify the issue, I’ll try to add some and keep you posted when I do, so that we can troubleshoot the issue. In the meantime, can you tell me what version of the Freebox you have? Not sure this is very relevant, but the more info, the easier it will be to understand what is going on :slight_smile:

You’re absolutely right, i shoud have start with all details.

I’m running hassbian up to date (system & HA) on a wired raspberry pi 3 B+.
The router is a freebox revolution r1 (3.5.2 firmware), rebooted during the issue to check if it was not from the router.

As a workaround at the moment i disabled the new applications associations on the router and it’s still working (status of tracked devices are up to date since few days with this).