My Home Assistant Dashboard alerts if my Victron Solar System last fully charged the Battery more than a week ago

A crescent-shaped gauge showing a needle pointing about 10 o'clock in the green band, with orange and red bands beyond that. In the centre it says "2 Days" and below that is the caption saying "Battery Last Fully Charged".

About two months ago we got woken in the middle of the night to the UPS system alarm screaming, and pitch darkness. The UPS keeps the Internet router alive, with the main solar system powering that. This should not happen as my solar system runs on a Lithium battery, and I have 24/7 audible alerts if the battery gets down to 20% for any reason. That night the battery was on around 37% if I remember correctly, and suddenly just shut off.

South Africa has had its heaviest load shedding this year, but even so, I always allow a good safety margin of 5+ hours on battery to cater for the odd 4-hour load shedding stages. So, this was really odd. But after speaking to the installers, they told me that as it was in the middle of Winter, I had been running my battery for weeks down to 30% or so, and it was never achieving a full 100% charge during those weeks. What had happened was, the State of Charge (SOC) % was no longer accurate as the battery needs a full charge into 100% until it reaches idle mode, to balance out the cells. With the imbalance, that 37% SOC showing was in fact the hard cut-off of the actual 10% average SOC that was reached = hard shut down. I also have the battery set to not preserve battery life (which would normally adjust the minimum SOC upwards, until a day where the battery charges fully).

The solution is quite simple: At least once a week, I should ensure the battery is fully charged, whether by solar or grid power. But how do you check that?

I monitor tons of metrics off the solar system already, including down to what tomorrow’s solar energy forecast is, the cloud cover for the next day, etc. So, this week I thought, why not write an automation to restart a timer every time the battery reaches a full charge, and warn me if this reaches 7 days, to do a full charge?

I already post the code for this home automation to a GitHub project repo, but I thought this time, let me actually open a discussion thread on the repo, so I could chat to myself as I went through the process. This will prove more useful for me next time I need to troubleshoot it, and also would help anyone else wanting to implement it (instead of trying to figure out all the separate bits of commented code).

The basics are working now, but before I upload the actual code changes, I’m just letting it run a bit to be sure that the warnings work, and that the timer does reset properly at full charge (its trigger checks for battery status changing from charging to idle, at 100% SOC). If there is some cell imbalance, the charging normally continues at 100% for a good 10 minutes or longer, and this needs to be allowed for.

I’m still pondering a bit around maybe automating the full charge process. There are two or three ways of doing it, but I also don’t want to waste grid power if I know the next day is going to be a good solar energy day. So possibly I can have HA look at the forecast for the following day, and if low, then charge fully from say 15:00, and switch back to normal usage mode.

See https://github.com/Danie10/gadgeteerza-homeassistant/discussions/6