patman15 / BMS_BLE-HA

This integration allows to monitor Bluetooth Low Energy (BLE) battery management systems (BMS) from within Home Assistant.
GNU Lesser General Public License v2.1
45 stars 9 forks source link

I would like to have an counter for each battery. The counter should incrase if a communication cyclus is performed #83

Closed Karatzie closed 1 week ago

Karatzie commented 1 week ago

Checklist

Please describe the enhancement you would like to have.

I am suspicious about the Bluetooth communication with the RB Pi 4 and the Supervolt batteries.
To compare the number of data communications between the two batteries over the course of the day, a counter was set up in the Batmon-ha.
This counter was integrated into each cycle.
If the curves were the same throughout the day, everything was fine.
In my energy dashboard I also had an LED symbol for active data transmission.
The counter should be reset automatically at the end of the day.

Additional context

Here is a coure curve of the counter: grafik At the moment I see a lot of gaps because the values are not changed. grafik This is my energie dashboard. You can see the LED for the communication. grafik

patman15 commented 1 week ago

If data update was successful, sensors (except RSSI and link quality which have a different logic) are available, otherwise they switch to unavailable, the link quality sensor does what you are asking for. It shows you how many of the last 100 cycles (each 30s) have been successful.

Karatzie commented 1 week ago

Hi Patrick. I check your comment and saw that the link quality only updates if the value is changed. At the end, I add following in your code: grafik This code forced a signal update without value changing. I have add an template helper by myself. {{ (as_timestamp(states.sensor.libatt14f6_batterie.last_changed)) }} This helper get the last chaged time of the battery value.

If this value is changed, the LED is switched on. I still observe some caps. grafik

But it is better than before.

Karatzie commented 1 week ago

I have set the update_interval to your value 30 seconds. I saw still observe gabs. grafik

patman15 commented 1 week ago

I check your comment and saw that the link quality only updates if the value is changed.

I would disagree with that statement, why do you think so?

I have set the update_interval to your value 30 seconds.

I'm not clear, which update_interval you mean.

I saw still observe gabs.

I can't follow your intention. What are you trying to proof or what do you want to achieve? I remember you are using the internal BT of the RPi4, correct? This one is known to have it's limitations, so it is quite unlikely that you can achieve 100% availability. If you want to go there, you need to change the physical setup unless you have spotted a bug in the integration. Currently, I'm not aware of any tough.

Karatzie commented 6 days ago

Hi Patrick,

thank you for your response.

I am now using an ESP32 Bluetooth proxy.

When I look at the link quality, I see 100% and last updated 22 hours ago. There is no new trigger from this entity. grafik It is possible that your integration sends an update to HA, but HA does not take the new value and the update information is not change.

I have set the UPDATE_INTERVAL: Final = 30 # [s] in the const.py to 15 seconds.

I don't want to prove anything.

I have had problems with the Bluetooth connection from the Raspberry Pi3 in the past. With the Raspberry Pi4 this has become even worse. But I need the Raspberry Pi 4 for ESPHome. I can no longer build FW with the RB Pi3. Your integration now offers Bluetooth proxy support.

In the battmon-ha a counter was integrated, which was increased by 1 with each Bluetooth query of the battery. This counter was reset each time the integration was started.

With the counter, a failure of the logic behind an interface is recognized immediately and there is no need to wait for the signals to time out. Frozen values can be recognized very quickly. There have been problems in the past when the counters have run out.

Just for your information: We uses these counters also for serial interfaces with our power plant control system. Here we can then switch to the redundant interface very quickly before the timeout is happen. In the system we had a timeout of 32 seconds.

I am now looking for a value from the battery that changes with every query via bluetooth in the Home Assistant. I would like to have this value as a trigger for my flashing LED in the energy overview. Unfortunately, there is no such value.

You can see here one gap over 45 seconds without an update of the update forced signal. grafik grafik It is possible, if no value from the battery is changed in a new bluetooth query, the send to HA code in youe integration will not perform. But that's just a guess on my part.

I can use your integration. The bluetooth connection is very good over a Bluetooth Proxy.

patman15 commented 6 days ago

Ok, now I think I know your issue. Probably you are misinterpreting the name of the values (which also happend to me). HA uses it's own logic. Debatable, but I'm bound to it unless HA changes them:

So in consequence everything works fine if you see the 100%. Since you are looking for some proof that the sensor values are actually updated (which is in HA logic, that they are available), you can have a look at the logic in the code, or trust my short explanation below:

I think the logic and reporting is very close to what you want if you consider the definitions correctly. Just to make it clear:

[!CAUTION] Neither Home Assistant nor this integration can be used for safety (ISO 26262) relevant operations! There are numerous issues with the Bluetooth code or dongles that can lead to stuck values that you cannot detect. So do not use the results for safety critical actions.

E.g. if the Bluetooth stack crashes and/or HA doesn't call the integration every 30s there is nothing the integration can do about it.

So long story short, in your case everything is fine, you can rely on the link_quality. If you think this not reliable enough, I would like you to think about the following case: "What if the BMS gets stuck and just continuously sends the same sensor values from some register although it's overheating?" The BMS is also not reliable itself ...

Hope that helps, enjoy your weekend, Patrick