I did some digging around and based on my limited knowledge, you can’t use a variable number in the badge section. Depending on how long the variable is, you can create a different push notification for each number. In my case, the number will theoretically never pass more than 6 or so.
Here is my example configuration I’ve fudged together so far:
one_beer:
alias: One Beer
sequence:
- condition: numeric_state
entity_id: input_number.beer_today
below: 2
- service: notify.iosapp_benjamins_iphone
data:
message: "{{ states.sensor.beer_today.state }} Beer Today"
data:
attachment:
url: https://iambendick.com/counter/img/push/IMG_2020.JPG
hide-thumbnail: false
push:
sound: "US-EN-Morgan-Freeman-Turning-On-The-Bar-Lights.wav"
badge: 1
category: "beer"
action_data: # Anything passed in action_data will get echoed back to Home Assistant.
entity_id: light.test
my_custom_data: foo_bar
two_beer:
alias: Two Beer
sequence:
- condition: numeric_state
entity_id: input_number.beer_today
above: 1
below: 3
- service: notify.iosapp_benjamins_iphone
data:
message: "{{ states.sensor.beer_today.state }} Beer Today"
data:
attachment:
url: https://iambendick.com/counter/img/push/IMG_2020.JPG
hide-thumbnail: false
push:
sound: "US-EN-Morgan-Freeman-Turning-On-The-Bar-Lights.wav"
badge: 2
category: "beer"
action_data: # Anything passed in action_data will get echoed back to Home Assistant.
entity_id: light.test
my_custom_data: foo_bar
so the counter.iosbadgecount number is correctly sent, but the app doesn’t react to this and doesn’t show any badge number…
Now interestingly if I replace my courtner with a number, it doesn’t work either since I changed the first data into data_template.
@robbiet480 am I doing something that’s unsupported here or is it a bug?
also, is it possible to send a “silent” notification to the app to reset the badge (so I don’t have to dismiss a notification on my phone)?
Did you ever get an answer to this? I am trying to do exactly the same thing and it is not working. Interestingly if I create a really basic script to send an IOS notification with a badge of 1:-
Wanted an easy way to manage badge number, just increase or decrement it. While searching I came across this topic so I’ll share my script in here if others would need something similar.
I created a helper input number element: input_number.app_badge_counter
Any automation or script that wants to edit the app badge counter, will just need to call one of these services to increase or decrement the badge counter. No notification will be shown by it, so each script can still send it’s own custom notification.
Hi!
I used this in my automations, to have the badge increase +1 every time the automation is run.
The problem is that this counter is never reset, so if the badge is 3, I open the app the badge disappears, at the next notification the badge is 4 and not 1
action:
- service: counter.increment
data: {}
target:
entity_id: counter.app_badge_counter
- service: notify.mobile_app_inanu
data:
title: Home Assistant
message: Test Badge
data:
push:
badge: "{{ states.counter.app_badge_counter.state }}"
mode: single
You need to reset badge to 0 using service call. So most likely it is not possible to reset counter just by opening application. One of the reasons I also stopped to use these.
I was seeing this as well this morning and figured it out: once I changed my helper from template to input_number, everything worked great in the following form: