Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC area mapping #415

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

PoC area mapping #415

wants to merge 3 commits into from

Conversation

timon37
Copy link

@timon37 timon37 commented Dec 23, 2024

As mentioned in #402 this is just to show the concept and allow anyone to test it, and not an actual "pull request".

The extension is renamed to 'Permuda' and all entities are prefixed with 'permuda' so that it can be used besides Bermuda and shouldn't conflict with it.

To test it just copy/link the 'custom_components/bermuda' folder as e.g. /var/lib/hass/custom_components/permuda then add the integration in home-assistant.

Currently I don't do any beacon power compensation, although the original code does and that might still work, I haven't tested it because I only have one...
So I'd recommend adding and callibrating only with one device at first, it has to be something that advertises continuously preferably quite often (e.g. 3 times per-second).
First just select it in "Configure / Select Devices" like in Bermuda.

To map an area:

  1. go to the area with a phone and your beacon device (probably also the same phone)
  2. click "Configure / Calibration 3: Mapping Areas"
  3. select your beacon device and the area you're in
  4. click submit to start gathering points for the map
  5. walk around the area with your beacon device,
    a. preferably naturaly pretending to do things you'd normally be doing
    b. you can click refresh to see how many points were captured
    c. note abort doesn't work atm... so don't accidentally walk into another area...
  6. once you've gathered enough data click Finish (initially aim for ~5-10sec of mapping, later you can add more)

You can clear specific areas or the whole mapping in "Configure / Calibration 1: Map Management".

Note that the area and some debug values are exposed as new entities "sensor.permuda_ Area" so you'd have to rename it or change your automations to actually use this instead of regular Bermuda.
Instead (at least initially) I'd recommend just opening the device and you'll see both the Bermuda and Permuda entities listed, there you can observe whether the Area changes differently and whether it's actually better or worse and where.

At the moment areas extend past their gathered points, so don't be surprised that you're likely mapped to (sometimes weird) areas when you're in a not-yet-mapped location.
You can try to limit that by mapping additional areas like "garden" or "elsewhere".

In tools there's a grah.py for visualizing the gathered points and tuning heuristics.
Just click "Download diagnostics" under the 3 dots next to "Configure", and run it: ./graph.py /path/to/diagnostics.json

Don't hesitate to ask questions or hack anything in the code, there's a bunch of tunables and alternative code that isn't exposed in the config yet.
Besides that I'd really like to see someone else's diagnostic.json file with a bunch of areas mapped!

timon37 Tomasz Borowik added 2 commits December 23, 2024 02:19
@Lash-L
Copy link
Contributor

Lash-L commented Jan 20, 2025

Hey @timon37 I went to give this a try and got the following logs:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/permuda/__init__.py", line 41, in async_setup_entry
    coordinator = BermudaDataUpdateCoordinator(hass, entry)
  File "/config/custom_components/permuda/coordinator.py", line 237, in __init__
    self.bmap_load()
    ~~~~~~~~~~~~~~^^
  File "/config/custom_components/permuda/coordinator.py", line 1444, in bmap_load
    self.bmap.bake()
    ~~~~~~~~~~~~~~^^
  File "/config/custom_components/permuda/common/map.py", line 394, in bake
    self.bake_mean()
    ~~~~~~~~~~~~~~^^
  File "/config/custom_components/permuda/common/map.py", line 429, in bake_mean
    self.area_count_mean = statistics.mean(self.area_count.values())
                           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/statistics.py", line 490, in mean
    raise StatisticsError('mean requires at least one data point')
statistics.StatisticsError: mean requires at least one data point

After fixing that with just an if statement that sets it to 0,

I get another error:

Traceback (most recent call last):
  File "/config/custom_components/permuda/coordinator.py", line 545, in _async_update_data
    device = self._get_or_create_device(service_info.address)
  File "/config/custom_components/permuda/coordinator.py", line 523, in _get_or_create_device
    device = self._get_device(address)
  File "/config/custom_components/permuda/coordinator.py", line 518, in _get_device
    if mac in self.devices:
              ^^^^^^^^^^^^
AttributeError: 'BermudaDataUpdateCoordinator' object has no attribute 'devices'

I am trying to run it along side my existing bermuda, so perhaps that is causing problems.

Happy to try it out, but seems like there are a number of roadblocks.

@timon37
Copy link
Author

timon37 commented Jan 20, 2025

Running alongside vanilla bermuda shouldn't be a problem, that's what I do locally.

I did manage to repro the first issue but couldn't repro the second:(
As far as I understand python I don't see how it could've happened since self.devices is set in the init.
Unless I guess bmap_load() failing cases init() to early out, but other parts of the code still get called (I guess since it's async?).

Nevertheless added a check for both, so if you feel like it you can try again.

I understand both of these hit before you tried to configure anything? (other than adding the integration)

@Lash-L
Copy link
Contributor

Lash-L commented Jan 20, 2025

Running alongside vanilla bermuda shouldn't be a problem, that's what I do locally.

I did manage to repro the first issue but couldn't repro the second:( As far as I understand python I don't see how it could've happened since self.devices is set in the init. Unless I guess bmap_load() failing cases init() to early out, but other parts of the code still get called (I guess since it's async?).

Nevertheless added a check for both, so if you feel like it you can try again.

I understand both of these hit before you tried to configure anything? (other than adding the integration)

I'm unable to configure a device at all - i haven't really gone into your code to figure out why. But I'd recommend removing Permuda entirely, and seeing if you are able to setup from a clean slate

image

@timon37
Copy link
Author

timon37 commented Jan 21, 2025

Yeah that's what I did.
Hmm just to be sure you aren't getting any more errors in the log right?

Which version of hass and bermuda do you have?
I'm on Core 2024.12.5 Frontend 20241127.8, Bermuda version is 0.0.0 for some reason.
I'm running directly on nixos so that might explain some of the difference.

Unfortunately I'll be out for the rest of the week, and I'm going to fosdem the weekend after that, so I won't have much time the next two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants