Last Notification Sensor sometimes does not update

Hello There,
I’m using HomeAssistant Core 2021.12.10 with the Android companion app, minimal flavor, on LineageOS with microG and magisk.
Mostly everything works fine.
I’m trying to utilize the last_notification sensor to get a rough daily step count out of samsung health.
The notifications regarding steps always have the same android.text and android.bigText, with the daily goal. The count itself is in android.title

Now sometimes the steps update fine, sometimes they don’t. If they do not update in hass and I go to the sensor settings in the app and look at the last_notification there it has the correct value. And the moment I tap it it will be updated in hass.

As I do not use many notifications for HA, often 2 of these step notificationa follow each other. So i assume that the app does not recognize the Notifications as different, and therefor does not update the sensor. Is there anything i can do about this? I’m not really a tec pro, sorry…
Greetings

Blubbel

You need the text of the notification to change. Some users make tasker to post a notification so it’s always changing. The Android app will not send an update if the state of the sensor has not changed.

Thanx for answering.
So the companion app does not recognize changes in android.title ? This would explain my Issues.
Is android.text the only field it checks?
I don’t use tasker but i sure can think of other ideas to tackle this.

state for the sensor is determined by either android.text and if its not supplied then it will default to android.title and if not available then just the package name.

There are too many different variations to account for here when you think about all apps in general. With tasker you should be able to have it create a notification any time you get a notification from the app you care for. Then you can have the sensor report on tasker and the app and you should see the state changing each time a notification is posted.

Why not change line 135 to val state = sbn.packageName + "\n" + (attr["android.title"] ?: "") + "\n" + (attr["android.text"] ?: "")? That way, any change would be detected.
If state got too long (longer than 255 chars), one could throw it through some hash function…

we are open source, feel free to test and submit a PR :smiley:

not necessary we already take care of that here

Sorry for my wording in advance, I’m in no way a programmer. At the moment android.title is an attribute, android.text also, as is .bigText and many else.
I was not able to identify the bit of code that checks if a new notification is identical to the one before.
My thoughts were: for sure, changed timestamp is irrelevant, not sure about appInfo, and a few else.
icon does not send an icon, so i would assume is not used?
Things were information for the user is transported are the three mentioned above, and then there is a thing called channelID I do not know about

So to me it seems if the check if something is different could be performed on text, bigText, and title, even if only the attribute changes then, it would be nice/could be useful.
At the moment I lack the knowledge how sensors work in home assistant, and how hass reacts when only an attribute changes, but not the state.
So I’m not even sure if this looks like a good idea to anyone but me. :smiley:

Attributes are not meant to designate a state change, they are meant to compliment the state and to provide more information about it. The check we do is against the state only per the HA core requirement and all sensors abide by this check.

that take(255) just cuts the state string short, if the change is after that, it won’t be noticed…

1 Like

Thanks for clarification! A little bit more to understand every day. so when an app makes it’s information in .text stay static and update only .title it won’t work, and I need a workaround.

HA core will give an error as the database requires us to send 255 characters only. We had an issue with this sensor previously where folks were getting nonstop errors.

the best work around people have used in cases where they have 1 app and the text doesnt change much is to use to tasker to post a notification so the state is always different.

Home assistant notification sensors are no longer working on companion. All other sensors work fine. But the notifications sensors are the only one that’s not working. Anyone else face the issue?

1 Like

If the state did not change then it won’t update, the state must change in order to send the next update.

I am using the last notification sensor to log notifications into home assistant from another android app. That app will often received a number of notifications in very quick succession, each different. Only one or some messages of the notification bursts show up in Home Assistant. Is there a fix for this?.

known issue some workarounds mentioned here