Another update! This time with the clearest possible depiction of the issue.
I am convinced that there is a missing code path or other bug that prevents the template sensor from being evaluated every time it should.
Background
Some time shortly after midnight, two things happened:
- The withing integration bug fired off again
- At least one of the Shelly devices on my network determined that there was a new firmware update available.
Here is the automation that manages the notification when there is a shelly device firmware update.
alias: Notify when Shelly Devices have new FW updates to apply
description: ''
trigger:
- type: turned_on
platform: device
device_id: 6<...>2a
entity_id: binary_sensor.shelly_2_5_<...>_firmware_update
domain: binary_sensor
id: some_id
# <... this repeats for each shelly device ...>
condition: []
action:
- service: persistent_notification.create
data:
message: Please check shelly devices
title: Shelly device has a pending FW update # Yes, i fixed the typo; you will see SHelly in screenshot.
- service: todoist.new_task
data:
content: Update Shelly Firmware
# ...
mode: single
And here is the automation in question that I keep referencing w/r/t the blue light.
alias: Toggle status light blue when HA has notifications pending
description: >-
A visual queue that something needs my attention
trigger:
- platform: state
entity_id: sensor.active_persistent_notifications
from: '0'
id: some-pending
- platform: state
entity_id: sensor.active_persistent_notifications
id: none-pending
to: '0'
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: none-pending
sequence:
- type: turn_off
device_id: d<...>b
entity_id: light.blue
domain: light
- conditions:
- condition: trigger
id: some-pending
sequence:
- type: turn_on
device_id: d<...>b
entity_id: light.blue
domain: light
default: []
mode: single
SO with that in mind, lets get on with the show!
What I Woke Up to
After waking up and making my way into the kitchen for some coffee, I noticed the indicator light was blue. Since my computer was still asleep, I used my phone to check what the notifications were:
Before dismissing any notification, I woke up my desktop and prepared to start taking screenshots / documenting.
I pulled up three instances of Lovelace and then dismissed went back to my phone to dismiss the “withings failure” notification.
I used my phone to dismiss because I wanted to rule out any websocket related issues. As soon as I dismissed the notification on my phone, the notification badge count dropped by one on my mobile and desktop. It is safe to say that there is no problem with websockets here; a button press on one device is reflected in real time on the other.
Look above, I want to call your attention to a few things:
- The notification badges are correct.
- The template sensor is not correct
- The template evaluation in dev tools is correct
After collecting and annotating that screenshot, I dismissed the only remaining notification; the shelly fw notification:
This time:
- The notification badges are correct; now reads 0.
- The template sensor is not correct. It isn’t an ‘off by one’ error… it straight up did not get evaluated!
- The template evaluation in dev tools is correct
With that, I wondered if there was some sort of code path that either the shelly or the withings notification were created through that does not result in the template sensor evaluation. I fired off a new test
notification:
This time:
- The notification badges are correct; now reads 1. The notification drawer has the expected value.
- The template sensor is correct. It has changed from
2
to 1
.
- The template evaluation in dev tools is correct
So then dismissing the test notification absolutely should result in all counts reading 0, right?! Well, i thought so, too.
This time:
- The notification drawer and badge both show 0. The expected result.
- The template sensor is not correct. It still appears as though it was never re-evaluated.
- The template evaluation in dev tools is correct
So then what would it take to force the template sensor to be re-evaluated!?
I went into server controls and reloaded the template entities
. The template sensor was updated and the notification light went from blue to off. Success!
I went to update the firmware on all but one of the Shelly devices and to make another cup of coffee.
While away, the shelly discovery script fired and the one device that didn’t get a FW update caused a notification to fire off again as expected / intended.
This time:
- The notification drawer and badge both show 1; the single notification created by the automation shown @ the top of this post.
- The template sensor is correct.
- The template evaluation in dev tools is correct
So what happens when I dismiss the shelly notification? If you’ve been paying attention, you know that the answer is not “the template sensor worked as it should have”
This time:
- The notification drawer and badge both show 0 as expected.
- The template sensor is ** not correct**; it is still behaving as though it was never evaluated. The indicator light is still blue / on.
- The template evaluation in dev tools is correct
So with that, I am convinced that there is an issue with the logic that schedules template sensors for (re)evaluation. In at least some (not yet fully understood) cases, dismissing a notification does not trigger re-evaluation…