Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp spike battery improvements #21

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

h3ss
Copy link
Contributor

@h3ss h3ss commented Jan 24, 2024

I finally managed to capture readings from an entire discharge cycle of a TempSpike battery. The battery reading sent by the device appears to be a reading in millivolts, and the discharge cycle is a non-linear function as you would expect in that situation.

To create a more accurate mapping of voltage to battery percentage, I used some machine learning to optimize a function in the form A*tanh(B*x+C)+D where A->D are variables that were optimized with TensorFlow. (I chose that function format simply because I noticed that the curve from the readings looked fairly similar to a tanh curve). This yielded a function whose output fit within about 1.8% of the actual data collected, which I think is good enough ;)

I also added clamping for both minimum and maximum values, just in case.

h3ss added 2 commits January 20, 2024 06:22
…ading from hardware, clamped minumum as well as maximum values just in case, and added comments about voltrage curve
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (19c07bf) 81.96% compared to head (7f9a985) 85.24%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #21      +/-   ##
==========================================
+ Coverage   81.96%   85.24%   +3.27%     
==========================================
  Files           2        2              
  Lines          61       61              
  Branches        8        7       -1     
==========================================
+ Hits           50       52       +2     
+ Misses          5        4       -1     
+ Partials        6        5       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@h3ss
Copy link
Contributor Author

h3ss commented Jan 24, 2024

imgpsh_fullsize_anim (5)
Battery curve comparison:

  • Blue line are device readings
  • Orange line is the predicted value

@bdraco bdraco merged commit c396f81 into Bluetooth-Devices:main Jan 24, 2024
9 checks passed
@bdraco
Copy link
Member

bdraco commented Jan 24, 2024

Thanks. Release will publish shortly

@bdraco
Copy link
Member

bdraco commented Jan 24, 2024

I'm not at my desk, so it'd be great if you could take care of bumping library in HA as well

@bdraco
Copy link
Member

bdraco commented Jan 24, 2024

I forgot to fix the commit message name so the release failed, I'll have to wait till I get back to my desk to do it manually

@bdraco
Copy link
Member

bdraco commented Jan 24, 2024

all sorted https://github.com/Bluetooth-Devices/thermopro-ble/releases/tag/v0.9.0 published

@h3ss
Copy link
Contributor Author

h3ss commented Jan 25, 2024

Thank you very much @bdraco !

I'm not at my desk, so it'd be great if you could take care of bumping library in HA as well

I went ahead and submitted this. My first time doing a PR to that repo so hope I got it right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants