Skip to content

Commit

Permalink
Notify when charge threshold is reached (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it authored Oct 8, 2022
1 parent 33aae2f commit 7e8d3ae
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 4 deletions.
355 changes: 355 additions & 0 deletions Garmin_BatteryGuestimate.prf.xml

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Garmin Battery Guesstimate

Shows the battery consumption over time and estimates how long the battery would last (better than the build-in estimation).
1. Shows the battery consumption over time
2. Estimates how long the battery would last (better than the build-in estimation)
3. Notifies the connected phone when a set threshold is reached during charging (to extend the battery lifetime)

Connect IQ store link: https://apps.garmin.com/en-US/apps/572b8232-7fb6-4e4f-a938-2395d0df3c7c

Expand All @@ -14,6 +16,8 @@ During a longer activity you can check how much battery charge you have lost so

Also, this app shows you nicely if you have gained any battery charge by solar.

As a small extra the app can help you extend the overall battery lifetime by configuring a [charging threshold](#charging-threshold), so you don't charge the battery to 100% but for e.g. only to 90%.

## Screenshots

![glance](screenshots/glance.png)
Expand All @@ -28,6 +32,7 @@ The battery status is collected every 15min in the background and this date is u
1. show the battery charge/discharge over time
2. calculate how long the battery might last
3. show a graph of the battery status
4. notify the user when the battery reached a specific level during charging (off by default)

## Usage

Expand All @@ -37,11 +42,13 @@ The battery status is collected every 15min in the background and this date is u
- in the details view use the UP/DOWN buttons to cycle through the different time periods
- in the details view press the GPS button to view the battery graph
- in the graph view use the UP/DOWN buttons to cycle through the different time periods
- set the charging threshold through the Connect IQ app if you want to receive a notification when the battery reached a specific level during charging

### Settings

Use the Connect IQ app to configure the widget.
1. set the time-frames to be displayed in the glance view
1. time-frames to be displayed in the glance view
2. charging threshold to send a notification to the connected mobile phone

## Different predictions of how much longer the battery will last

Expand Down Expand Up @@ -69,6 +76,18 @@ For the case that you have recharged your watch with the cable, or you don't exp

In both cases the prediction is rather pessimistic, so it will always floor decimal results (an estimation of 5.9h will show 5h)

## Charging Threshold

Setting the `Battery Charge Threshold` to a value higher than 0 will cause the watch to send a notification to the connected phone when reaching that value during charging.
The check happens every 15min, so you might want to set the threshold to a relatively low value, because depending on your watch and the charger the charging time might be pretty short, so it can easily happen that by the time the check happens the battery is already charged much higher value.

**The notification is actually a hack!** There is no easy way to send a notification to the phone without creating a whole companion app. The hack is to request the phone to open a website. When the set threshold is reached the phone will display a notification saying that Garmin IQ wants to open the website `http://battery-level-reached.garmin`.
On an Android phone you can use [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm&hl=en) together with [AutoNotification](https://play.google.com/store/apps/details?id=com.joaomgcd.autonotification&hl=en) to intercept the notification and to display something more sensible. Import [this tasker profile & task](https://github.com/individual-it/BatteryGuesstimate/blob/master/Garmin_BatteryGuestimate.prf.xml) for that.

## Permissions
- run in the **Background**: needed to check the battery status every 15min
- **Send/receive** information to/from the Internet: needed to send the notification to the phone. **NO** information is send/received to/from the Internet! It only sends a notification to the phone requesting to open a dummy website to notify the user about the reached threshold.

## supported devices
- Garmin Instinct 2 Series
- Garmin Fenix 6 Series
Expand Down
1 change: 1 addition & 0 deletions app/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</iq:products>
<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="Communications"/>
</iq:permissions>
<iq:languages/>
<iq:barrels/>
Expand Down
6 changes: 5 additions & 1 deletion app/resources/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<properties>
<property id="glance-timeframe-0" type="number">1</property>
<property id="glance-timeframe-1" type="number">2</property>
<property id="charge-notification" type="number">0</property>
</properties>
<settings>
<setting propertyKey="@Properties.glance-timeframe-0" title="First time-frame in glance-view">
Expand Down Expand Up @@ -73,7 +74,10 @@
<listEntry value="1248">13 days</listEntry>
<listEntry value="1344">14 days</listEntry>
</settingConfig>
</setting>
</setting>
<setting propertyKey="@Properties.charge-notification" title="Battery Charge Treshold. Notify the mobile phone when the watch reaches this battery level during charging">
<settingConfig type="numeric" min="0" max="100"/>
</setting>
</settings>
</resources>

11 changes: 11 additions & 0 deletions app/source/BatteryGuesstimateApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Toybox.Background;
import Toybox.System;
import Toybox.Time;
import Toybox.Math;
import Toybox.Communications;
using Toybox.Application.Properties;

(:glance)
const MAX_STEPS_TO_CALC = 24*4*14; // 14days
Expand Down Expand Up @@ -96,6 +98,15 @@ class MyServiceDelegate extends System.ServiceDelegate {
Storage.setValue(circularBufferPosition, systemStats.battery);
System.println("circular buffer " + circularBufferPosition + " => " + systemStats.battery);
Storage.setValue(CIRCULAR_BUFFER_LAST_POSITION_STORAGE_NAME_V2, circularBufferPosition);

var chargeNotification = Properties.getValue("charge-notification") as Integer;
if (systemStats.charging == true && chargeNotification > 0 && systemStats.battery >= chargeNotification) {
Communications.openWebPage(
"http://battery-level-reached.garmin",
{},
{}
);
}
Background.exit(true);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
</iq:products>
<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="Communications"/>
</iq:permissions>
<iq:languages/>
<iq:barrels/>
</iq:application>
</iq:manifest>
</iq:manifest>

0 comments on commit 7e8d3ae

Please sign in to comment.