sebr / bhyve-home-assistant

Orbit BHyve custom component for Home Assistant
MIT License
251 stars 42 forks source link

Intermittent battery reporting #209

Closed aleck011mi closed 4 months ago

aleck011mi commented 1 year ago

Describe the bug Recently, the battery graphs for my Bhyve XD hose timers (both 1 and 4 port) have been showing 0% battery most of the time, If I view the history graph, I will be able to see the actual SoC listed sometime in the last 24 hours. Sometimes it only seems to report correctly once in a day, and other times many times. The vast majority of the time, it is 0% however.

Expected behaviour The battery is correctly reported at all times.

BHyve devices 1 Bhyve XD - 1 port timer 2 Bhyve XD - 4 port times

Device Diagnostics Can attach in the next couple days.

not-an-IT-pro commented 1 year ago

They do - randomly - report on a gauge card. Any time that's happened in my experience it hasn't "stuck". ie...I see it at some point and then, 5 min later...it's gone. Sometimes connecting to a device (mine are all 24639s and BT/WiFi connected) the gauge will show a result some minutes later. Sometimes not. AFAIK this started with BHyve's Firmware v58. There are posts on the HA forum https://community.home-assistant.io/t/integration-with-orbit-b-hyve-irrigation-system/39688/367 about this with some pix. Sorry, I'm not a programmer...just a tech user with an itch. Happy to provide deets if someone can tell me what would help.

This error does, however, come up for me on a restart - no idea if related:

Logger: homeassistant.components.switch Source: custom_components/bhyve/switch.py:246 Integration: Switch (documentation, issues) First occurred: 3:45:52 PM (1 occurrences) Last logged: 3:45:52 PM

Error while setting up bhyve platform for switch Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/bhyve/switch.py", line 200, in async_setup_entry BHyveProgramSwitch( File "/config/custom_components/bhyve/switch.py", line 246, in init device_name = device.get("name", "Unknown switch") ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'

not-an-IT-pro commented 1 year ago

@sebr Hopefully I've understood your instructons correctly as there are now a bunch of DEBUG entries in my log...attached! Two days worth (I'm still collecting them, if useful.) BHyve-HA debug log.txt

Shredder5262 commented 1 year ago

My battery level has not been reporting most of the time as well, i've noticed. Interestingly, the very moment I navigated into the Orbit app to check the battery information within the app itself, HA started reporting the battery level. 2023-08-08 00_15_20-Andrew Dashboard – Home Assistant - Vivaldi

not-an-IT-pro commented 1 year ago

@Shredder5262 Agree - although curiously, not every time. Mostly...but not all connections to units result in a "live" value.

But they ALL have "historical" values similar to what you show above. Clearly being read...just not being translated right away.

sebr commented 1 year ago

@aleck011mi @not-an-IT-pro @Shredder5262 can you please upload your device diagnostics? This is where the battery data is read from and it will help me track it down.

I have added some extra debugging locally and it shows that the battery results are being reported regularly:

2023-08-09 21:52:37.869 DEBUG (MainThread) [custom_components.bhyve.sensor] Front Garden battery level: 37
2023-08-09 21:52:37.925 DEBUG (MainThread) [custom_components.bhyve.sensor] Backyard battery level: 49
2023-08-09 21:52:38.342 DEBUG (MainThread) [custom_components.bhyve.sensor] Back Vegetables battery level: 51
2023-08-09 21:57:37.056 DEBUG (MainThread) [custom_components.bhyve.sensor] Backyard battery level: 49
2023-08-09 21:57:37.059 DEBUG (MainThread) [custom_components.bhyve.sensor] Back Vegetables battery level: 51
2023-08-09 21:57:38.017 DEBUG (MainThread) [custom_components.bhyve.sensor] Front Garden battery level: 37
not-an-IT-pro commented 1 year ago

@sebr As requested, device diags attached. I'm happy to do whatever you need....(but I'm no programmer, so need instructions, LOL). Three similar, but different devices, attached. config_entry-bhyve-a326b7c3e2aa0207177a666f1add63df.json (3).txt config_entry-bhyve-a326b7c3e2aa0207177a666f1add63df.json (2).txt config_entry-bhyve-a326b7c3e2aa0207177a666f1add63df.json (1).txt

sebr commented 1 year ago

@not-an-IT-pro thanks for sharing, this is interesting - your devices are reporting battery levels not as a percentage, but as millivolts:

[{
  "name": "Rear spigot",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 2490
  }
},
{
  "name": "not in use",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 2770
  }
},
{
  "name": "hydrant2",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 2820
  }
},
{
  "name": "Front new",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 3290
  }
}]

Devices which I have report as follows:

{
  "name": "Backyard",
  "type": "sprinkler_timer",
  "battery": {
    "percent": 96,
    "charging": false
  }
}

A couple of follow ups:

  1. Does the BHyve XD device use 2 AA batteries (i.e. 3V)?
  2. How does the app display the battery for your device? Can you share a screenshot?
not-an-IT-pro commented 1 year ago

Yep- they all use 2AA batteries - it never occurred to me that the mv would be millivolt. image

Curiously from the thread on the HA forum, I've uploaded a screencap of the same reporting, using a statistics base per the discussion but the values show, respectively as 100%, 29% and 75%....which although similar to what B-hyve reports...isn't quite the same.

sebr commented 1 year ago

I believe I have fixed this in #215 and it is released as a beta in 3.2.1-beta1.

@not-an-IT-pro @Shredder5262 can you please install this beta (you may need to enable this in HACS first) and LMK how you go?

not-an-IT-pro commented 1 year ago

Initial observation is that battery % reports....but it's quite different to what I'm seeing on the B-Hyve app or on the unit itself.

Particularly my "low" one ... which variously reports as 83% (your new beta) and 13% B-Hhyve app. Not quite sure what accounts for that though. Thinking this is a numerical translation error? The other two batteries (both either 100% or "high 90s" look normal. image

sebr commented 1 year ago

@not-an-IT-pro very curious... the value for your Rear Spigot device's battery level was:

{
  "name": "Rear spigot",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 2490
  }
}

Which I have implemented as: 2490 / 3000 * 100 = 83%. I can't back-solve to a number anywhere close to 13%...

I have added extra logging in 3.2.1-beta1 which reports battery levels more verbosely. Can you please enable debug logging and upload after a few days?

The spikes you have in your chart are curious as they are indicative of the API returning battery data inconsistently (since the values are being cleared).

Thx

not-an-IT-pro commented 1 year ago

@sebr Will do! Yes - it's rather peculiar and two things occur...although the App returns values on a regular basis, quite often the Integration does not -- or just says the value can't be read (you know...the long error message instead of the pretty gauge!).

But I went and physically looked at the reporting on the unit itself and it shows a pretty low battery level. What I may do - depending on time available - is swap those two batteries for ones in a different unit. That would eliminate the issue of the unit itself misreporting the levels....or confirm that is what's actually occurring.

Shredder5262 commented 1 year ago

@not-an-IT-pro After installing the beta, my battery level is showing Ha shows 90% while the app shows the device is 54%, I feel the app is accurate. If at all possible i would prefer a whole number, but if not possible at most 2 decimal points. 2023-08-24 20_36_20-Settings – Home Assistant - Vivaldi

not-an-IT-pro commented 1 year ago

@Shredder5262 That you can fix by changing the precision in the settings. So it seems a similar problem to mine with the translation of the amount.

@sebr I'm pooched for a couple of weeks - our house is in the middle of the British Columbia fire zone and we just left as we had the worst air quality in the world for three days running...so it seemed like a good bet to "not be there". We'll return in a couple of weeks and I'll be able to get back to testing.

Shredder5262 commented 1 year ago

@Shredder5262 That you can fix by changing the precision in the settings. So it seems a similar problem to mine with the translation of the amount.

somehow between the time of my post and looking again a few minutes later, it fixed itself to one decimal point and on a card shows a whole number....with home assistant, based on my experience, it's typical behavior for things like that to happen at this point, that piece is working. Regarding the inaccuracy, that piece still exists. Thank you for doing the work to update this.

sebr commented 1 year ago

@Shredder5262 can you also please enable debug logging and attach after a few days?

not-an-IT-pro commented 1 year ago

@Shredder5262 ... it's @sebr who is doing the work as the developer/programmer. I'm just a dumbass using the product and doing what testing I'm able to (or told to LOL, with instructions....).

Shredder5262 commented 1 year ago

My mistake, thanks @sebr
anywho, here is a debug log, I can let this run for longer if need be. home-assistant_bhyve_2023-08-27T04-20-29.442Z.log

erikjlane commented 11 months ago

@not-an-IT-pro very curious... the value for your Rear Spigot device's battery level was:

{
  "name": "Rear spigot",
  "type": "sprinkler_timer",
  "battery": {
    "mv": 2490
  }
}

Which I have implemented as: 2490 / 3000 * 100 = 83%. I can't back-solve to a number anywhere close to 13%...

That's not how batteries work. Once you hit the ballpark of 1.1 or 1.0V, an alkaline battery is basically empty. They don't go all the way to zero: https://www.powerstream.com/z/AA-100mA.png (from here: https://www.powerstream.com/AA-tests.htm)

Using just a straight line approximation from saying the batteries are done at 1.1V, means 2.2V is 0%, then 2.49V is ~36%. Still not 13%, but at least in the ballpark.

The equation shown on this page: https://devzone.nordicsemi.com/f/nordic-q-a/28101/how-to-calculate-battery-voltage-into-percentage-for-aa-2-batteries-without-fluctuations results in a calculation of 10% for a voltage of 2.49... so that's pretty close to their answer. (Though my batteries are 2690mV according to the home assistant diagnostics, and show as 58% in the app, so still not the exact mapping that B-Hyve is using.)

Shredder5262 commented 11 months ago

I see this issue is now closed, Has this been resolved? The battery reporting i see is now a percentage, but the calculation being done is inaccurate. HA says my battery level is 90%, but the b-hyve app states 57%.

sebr commented 10 months ago

I haven't been able to determine an appropriate equation to estimate the battery percentage from the mv value. I don't have a bhyve device which reports these values. If anyone can help, that would be appreciated.

austin20202020 commented 10 months ago

I have the same problem. The mV range should be between 2-3v, so 2000-3000mv. So an equation could be [(mv reported - 2000) / 1000] * 100 = battery % remaining. Can be further simplified to [(mv reported - 2000) / 10 = battery %]. This wont be strictly accurate due to variances in battery chemistry, but this will at least get us close

asutcliffe38 commented 10 months ago

If it helps at all, this is the device i have https://www.amazon.com/dp/B09KJZKVNS?ref=nb_sb_ss_w_as- I don't know what math equation would be needed to make the battery levels accurate, and prefer not to know.

I haven't been able to determine an appropriate equation to estimate the battery percentage from the mv value. I don't have a bhyve device which reports these values. If anyone can help, that would be appreciated. reorder_k0_1_6&amp=&crid=2W63EML2HKZTR&amp=&sprefix=b+hyve

sebr commented 4 months ago

It seems that BHyve have started adding in the percent attribute to events which previously only had the mv value. If this is consistently applied (it's impossible for me to know without all devices on hand), release 3.2.4 should resolve this issue.

Please let me know if you are still experiencing issues with battery reporting after upgrading and I will reopen this issue and implement further measures to progress this.