home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.82k stars 30.08k forks source link

Aranet does not update continiously #96116

Closed nathansamson closed 1 year ago

nathansamson commented 1 year ago

The problem

Aranet is not being tracked. (note I am not sure this is even a software issue, but I am not sure how to diagnose this further if its an hardware issue)

This integration worked before (I think it stopped working around the 2023.2 update but I am pretty sure it has nothing to do with the upgrade...

Previously every 5 minutes a new datapoint (temperature and CO2) was measured and logged. At some point this stopped working

(In grafana you can see the exact moment this happened, aroung beginning of may). image

In the beginning I thought this was due to my aranet being at low power (<15% at the end) so I swapped batteries. But even with new full batteries this is not working correctly anymore.

Every time HA restarts it does log a point though (proving that the bluetooth connection still works).

During the night I also (sometimes) see that data gets logged often, but then it stops working

image

What version of Home Assistant Core has the issue?

core-2023.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

aranet

Link to integration documentation on our website

https://www.home-assistant.io/integrations/aranet/

Diagnostics information

home-assistant_aranet_2023-07-07T18-02-29.645Z.log

(Note: I don't think it contains anything specific for this integration)

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @aschmitz, mind taking a look at this issue as it has been labeled with an integration (aranet) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `aranet` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign aranet` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


aranet documentation aranet source (message by IssueLinks)

aschmitz commented 1 year ago

Well, that's odd. I'm not really sure what might be causing it, but it spontaneously working sometimes at night seems like it's more likely to be a wireless or hardware issue than a software one, especially if your logs aren't showing anything relevant.

I guess a few debugging questions:

  1. What version of firmware is on your Aranet4? Has it changed since shortly before it was last working reliably? (I assume not, and I'm not aware of new versions, but maybe there's an issue with a new one?)
  2. Do you have other devices connected to Home Assistant via Bluetooth? Any that are using BLE broadcasts? (Are they all working okay?)
  3. How is Bluetooth configured with Home Assistant for you? (Built-in hardware on the host? An ESPHome Bluetooth proxy?)
  4. How far apart are your Aranet4 and the relevant Bluetooth receiver? Does it get better if you move them closer together?

Also, if you have an ESP32 board with ESPHome (or that you can put it on for testing) and you're not already using it, setting one up as a Bluetooth proxy might be worth a try. You shouldn't need any further configuration to make the Aranet4 work with it other than adding the esp32_ble_tracker and bluetooth_proxy components and adding the ESPHome to Home Assistant: Home Assistant should pick up all of the BLE advertisements regardless of where they come from.

nathansamson commented 1 year ago

Well, that's odd. I'm not really sure what might be causing it, but it spontaneously working sometimes at night seems like it's more likely to be a wireless or hardware issue than a software one, especially if your logs aren't showing anything relevant.

Yes, Thats what I kind of figured. Glad you are willing to help me debug this problem although its probably as you say not a software issue (at least on HA).

I guess a few debugging questions:

1. What version of firmware is on your Aranet4? Has it changed since shortly before it was last working reliably? (I assume not, and I'm not aware of new versions, but maybe there's an issue with a new one?)

I use version 1.3.5, not sure when I upgraded. Either a long time ago (before problems started) or when I was having problems and looking at my phone and saw there was an update. But feels unlikely its the direct cause.

2. Do you have other devices connected to Home Assistant via Bluetooth? Any that are using BLE broadcasts? (Are they all working okay?)

No other devices.

3. How is Bluetooth configured with Home Assistant for you? (Built-in hardware on the host? An ESPHome Bluetooth proxy?)

Built in on the host. This is an intel NUC machine. (I would expect a rather sensible bluetooth receiver that should be able to pick the signal up).

4. How far apart are your Aranet4 and the relevant Bluetooth receiver? Does it get better if you move them closer together?

Couple of meters (always has been the same distance). I've even put up extended range on the aranet and moved it almost on top of the intel nuc as well. Does not seem to make any difference.

Note my windows computer which also has bluetooth seems not be able to find the device (same location as the nuc). (using this to see the data https://kasparsd.github.io/sensor-pilot/). I am wondering if something changed so it breaks some bluetooth implementations (but would be weird if both windows and linux are affected, maybe it depends on bluetooth chip...)

Even when my phone finds it immediately after un-pairing on my phone and re-adding device.

I also was able to pair (from several meters away) with my tablet which never made a connection before. (I had to enter the pin shown on the device proving that the aranet still accepts new connections).

Ill try with my linux laptop later... (although I am not sure what that would proof...)

Also, if you have an ESP32 board with ESPHome (or that you can put it on for testing) and you're not already using it, setting one up as a Bluetooth proxy might be worth a try. You shouldn't need any further configuration to make the Aranet4 work with it other than adding the esp32_ble_tracker and bluetooth_proxy components and adding the ESPHome to Home Assistant: Home Assistant should pick up all of the BLE advertisements regardless of where they come from.

I think I could try this (have to dig into my device list but pretty sure I could do this). But not sure what this would proof...

nathansamson commented 1 year ago

Hi

Ok I think its a rogue device somewhere in the neigberhood flooding the airspace.

I tried https://github.com/Anrijs/Aranet4-Python directly to see if that worked from my computer at first I could see my device when running aranetctl --scan. Note I could not pair my computer with it (but It discovered it at first)

Then trying to see why the pairing did not work I started wireshark with bluetooth monitoring.

Not immediatly but after a minute or so I started to see floods of Advertisements.

When I then ran the aranetctl command again I got this

[beeple@carbon beeple-infra]$ aranetctl --scan
Looking for Aranet devices...
=======================================
  Name:     7C-8E-72-86-48-AB
  Address:  7C:8E:72:86:48:AB
/home/beeple/.local/lib/python3.11/site-packages/aranet4/aranetctl.py:165: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  print(f"  RSSI:     {advertisement.device.rssi} dBm")
  RSSI:     -80 dBm

=======================================
  Name:     6B-A2-BF-EC-52-B2
  Address:  6B:A2:BF:EC:52:B2
  RSSI:     -66 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -87 dBm

=======================================
  Name:     3A-60-3D-15-B0-DE
  Address:  3A:60:3D:15:B0:DE
  RSSI:     -98 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -92 dBm

=======================================
  Name:     6C-00-16-C8-B0-B4
  Address:  6C:00:16:C8:B0:B4
  RSSI:     -95 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -87 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -99 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -92 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -88 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -98 dBm

=======================================
  Name:     6B-A2-BF-EC-52-B2
  Address:  6B:A2:BF:EC:52:B2
  RSSI:     -62 dBm

=======================================
  Name:     6C-00-16-C8-B0-B4
  Address:  6C:00:16:C8:B0:B4
  RSSI:     -95 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -91 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -92 dBm

=======================================
  Name:     6B-A2-BF-EC-52-B2
  Address:  6B:A2:BF:EC:52:B2
  RSSI:     -65 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -96 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -92 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -92 dBm

=======================================
  Name:     70-6B-42-40-C9-42
  Address:  70:6B:42:40:C9:42
  RSSI:     -99 dBm

Scan finished. Found 0

Now the question becomes: How do I find this rogue device in my appartment block (it might even be neighbours?)

aschmitz commented 1 year ago

Yeah, that does seem like a relatively difficult environment for BLE advertisements. I suspect it's related, though I guess it would be interesting to know if Wireshark sees the advertisements from the Aranet4 at all in some normal amount of time. If so (but aranetctl doesn't see it), it might be possible that there'd be some way to improve pybluez to catch them.

Either way, I suspect figuring out how to decrease the level of Bluetooth(-frequency) noise in your area would probably be helpful, but in an apartment block I suspect it would be difficult.

nathansamson commented 1 year ago

The overload of Bluetooth in the environment did not feel right to me. For one because I never have any trouble connecting to it with my phone.

So I used the Terminal and SSH add-on to run commands on the nuc directly. I installed https://github.com/Anrijs/Aranet4-Python

And then I ran aranetctl --scan on the NUC (The home assistant)

It logged a datapoint. Then I waited some time. No datapoints where logged. (In this period of 10 minutes 2 datapoints should have been logged)

I ran the command again I immediatly see a new datapoint in grafana.

So nothing wrong with Bluetooth (at least at this moment) but no continuously monitoring of aranet automatically...

It almost feels like the bluetooth device goes to sleep until something (in this case aranetctl) wakes it up explicitly?

aschmitz commented 1 year ago

Do you have the "smart home integration" feature enabled in the Aranet app settings? That should be making it give a BLE advertisement every N minutes, and shouldn't require a connection (which is why we were able to use the early ESPHome BLE proxying, which didn't support active connections). If that's enabled but you're still not seeing it except when you do try to make an active connection, I'm pretty confused about what might be happening. :confused:

nathansamson commented 1 year ago

Do you have the "smart home integration" feature enabled in the Aranet app settings? That should be making it give a BLE advertisement every N minutes, and shouldn't require a connection (which is why we were able to use the early ESPHome BLE proxying, which didn't support active connections). If that's enabled but you're still not seeing it except when you do try to make an active connection, I'm pretty confused about what might be happening. 😕

Yes smart home integration is enabled. I don't know much about bluetooth, but I think the aranet --scan is also just looking for BLE advertisemsnets. And from what I can see they come in a couple of times per second. Or is that something else...?

Also its weird that when I do aranetctl --scan in the background the Integration picks something up but when I don't run that it doesn't.

From what I can see in the aranetctl code it also just listen for BLE Advertisements (via https://bleak.readthedocs.io/en/latest/api/scanner.html) and doesn't connect to a particular device

aschmitz commented 1 year ago

You make a good point with BleakScanner. I think aranetctl is calling BleakScanner with mostly-default options which would mean it's actually getting a scanning_mode of active by default. It wouldn't surprise me if any response it was getting would also be received by the HA integration, which would explain the behavior you're seeing where it shows a data point once.

What I don't really understand is why the device isn't regularly sending BLE advertisements regardless of whether there's a scan going or not. (I suppose another option might be if your Bluetooth adapter / stack is only passing them back when it thinks there's some sort of active scanning going on, but you said a lot of things showed up in Wireshark, so either Wireshark is doing that, or that's not what's happening.)

I suppose it would be interesting to let Wireshark run for some multiple of your Aranet4 update frequency (for example, 6 minutes if it's set to 5) and see if you see the Aranet4 announcing anything or not (and if you do, if HA sees it as well). If it doesn't, running Wireshark while you then run aranetctl --scan to confirm you see a BLE advertisement then would probably at least confirm whether you're seeing them at all in Wireshark (and potentially what scanning looks like, though I'm not sure that's helpful).

That said, if active scanning is the only way to get this to trigger with your device, I'm not really sure what to do: the normal HA infrastructure is geared towards passive reception of BLE advertisements, and I assume active scanning would lead to lower battery life on devices that are responding. (It would also just be really weird to get such a different behavior from your device and anything I can replicate on mine.)

nathansamson commented 1 year ago

It seems someone else is having similar problem (https://forum.aranet.com/all-about-aranet4/aranet4-integration-with-home-assistant/)

It might be the filter in wireshark but even after waiting 10 minutes+ (interval is 5 minutes) I do not receive any data on my laptop either, while I do when running aranetctl --scan

My suspicion its either a broken device (although weird that this would be the only broken thing) or a firmware upgrade (to 1.3.5 but as mentioned before I a not sure when I ran this)

I've opened a support ticket with aranet directly, maybe they can confirm the 1.3.5 firmware issue.

For now I am closing this issue as it seems its not the fault of the integration (although I am thinking should it be an option in the integration to enable active scanning with an interval?)