# Battery level prediction model

I have the idea of develop a model that predicts the battery charge level of my system for now until the following 5 days. The battery is charged using a solar panel. I am writing my code in Python 2.7 . I am able to measure the battery level in % (%100, 90%, 80%...%10). The model does not be very accurate, %10 error is acceptable.

To predict battery level I have only two parameters, current state of charge in % and the UV radiation level from and scale of 0 to 11 (However higher values than 11 are possible but not likely).

The idea to predict the battery level is to first obtain some empirical data day by day at the same time (2 hours after sunset to get rid of surface charge). The data would have the this format.

DAY UV %

1 6.5 80

2 8.2 90

3 4.5 60

......

I want first to obtain some values for a month and then create and algorithm or something like that to obtain a model or make a prediction of what battery level I will have within 5 days. Thanks to https://openweathermap.org/api I have the prediction of UV radiation for 5 days.

The problem is that I don't know how to manage this information or what tools I can use. To predict that battery level I know that need to look at current battery level and the UV prediction of the following 5 days. But I don't know how to make a model with the obtained data.

I was thinking to get the difference of battery level between to days and calculate the charging/discharging rate with and UV radiation level, but that does not work because charging/discharging rates are not same with %20 as current battery level of %80 as current battery level. I can also make an average UV radiation for the 5 days and try to obtain a linear regression...

Any idea or suggestion is welcomed.

Thanks a lot,

Ander.

• ..your battery has a solar cell charger?
– Ewan
Aug 29, 2018 at 9:49
• Yes of course, I forgot to mention that... Aug 29, 2018 at 9:53
• I've understood that battery level is notoriously difficult to determine. It took some study for modern smart phones to be able to (within reason) accurately represent battery life, as the assumption that battery life is linear with how much charge it has is wrong. I don't know how you're gauging current battery level, but if it is directly through voltage, then it's not going to be linear even if the charge is.
– Neil
Aug 29, 2018 at 10:05
• This is more a simulation engineering question than a software engineering one. It sounds like you are asking about how to model a physical system, less about how to implement your model in software. While I'm not sure on which site this question might be more appropriate, it is off-topic here.
– Hulk
Aug 29, 2018 at 10:26
• It is interesting, but I have to agree with Neil that it is probably harder than you think to come up with an accurate model for something like this. There are lots of non-linear effects, and even the capacity of the battery will not remain constant over time.
– Hulk
Aug 29, 2018 at 10:34

So obviously if you use the battery really hard on day 2 it will run out faster than if you didn't, you have no way to predict that.

Your battery presumably discharges at some minimum rate, so I would base the predictions off the assumption that the device will be on standby.

I will also assume a linear charge and discharge rates

Charge can then be expressed as

``````charge = initialCharge - (dischargeRate * t) + (rechargeRate * t)
``````

where

``````rechargeRate = rechargeConstant * UV
``````

iterate over the days and you have your prediction.

• The battery consumption is practically the same all the days. And what about dischargeRate, how can I get that? Aug 29, 2018 at 10:45
• @Andermutu you could measure it - just track how fast your battery is drained when you do not charge it.
– Hulk
Aug 29, 2018 at 10:48
• With a real solar charger, your `rechargeRate` will probably also depend on other factors in addition to the UV radiation rate - temparature may be relevant, for example.
– Hulk
Aug 29, 2018 at 10:57
• @andermutu how long will the device function without any sun?
– Ewan
Aug 29, 2018 at 11:06
• Hi @Edwan Without the sun will not function, it will be slept until sunrise with minimum consumption. Aug 29, 2018 at 11:13