home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.3k stars 636 forks source link

Last Notification Sensor doesn't trigger automation again when the same notification is displayed more than once #1253

Closed subism-dev closed 3 years ago

subism-dev commented 3 years ago

Home Assistant Android version: 3.0.2-full

Android version: Android 11

Phone model: Pixel 4 XL

Home Assistant version: 2020.12.0

Last working Home Assistant release (if known):

Description of problem:

I have a smart washing (laundry) machine... It's not so smart. It has an app with very limited functionality. Pretty much the only useful thing it does is send a notification to my phone once my washing cycle has completed.

I am using the Last Notification Sensor on the companion app, and have added my washing machines app to the allowed apps for the sensor.

I have also added an automation in Home Assistant that uses a state trigger to announce via TTS when the washing cycle is completed.

It works great, the first time... However, if I am having a day of doing laundry, I only ever get notified when the first load has completed. The completion of subsequent loads doesn't trigger the automation.

I believe that this is because the notification that my laundry app sends is always the same, and since it is the only allowed app, the state data never really changes?

I'm including an example of the state as seen in home assistant, it is always consistent, no matter how many times I receive the notification:

State

Your washing cycle has been completed

State Attributes

android.appInfo: ApplicationInfo{4ca67fb it.hoover.wizard}
android.bigText: Your washing cycle has been completed
android.infoText: null
android.largeIcon: null
android.progress: 0
android.progressIndeterminate: false
android.progressMax: 0
android.reduced.images: true
android.remoteInputHistory: null
android.showChronometer: false
android.showWhen: true
android.subText: null
android.template: android.app.Notification$BigTextStyle
android.text: Your washing cycle has been completed
android.title: null
package: it.hoover.wizard
friendly_name: Pixel 4 XL Last Notification
icon: mdi:bell-ring

I may be missing an obvious and pre-existing solution, so apologies if that's the case.

If not, maybe adding a state attribute to the last notification sensor with a timestamp of when the notification was received would be beneficial.

Thanks, great work on the app by the way, it's awesome sauce!

Additional: As i was about to hit send on this, my Nest Hub suddenly announced that "Your washing cycle has been completed".

I had run 2 washing cycles this evening, after the first one completed, a notification came through to my phone, and the TTS was announced.

The second washing cycle finished 23 minutes ago, and the notification came through to my phone straight away, but no automation/tts was triggered.

I had just opened up the Home Assistant Companion app and navigated to the last notification sensor settings to check that there was no extra information I wanted to include and the TTS automation triggered.

Just to test further, I backed out to the main screen of the app, and then navigated to the last notification sensor settings again, but the TTS Automation ddn't trigger again ¯_(ツ)_/¯

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):

Screenshot of problem:

Additional information:

dshokouhi commented 3 years ago

Can you check the logbook for the state changes and also share the automation you used?

Edit: also if the text is exactly the same then we do not send that state data to your HA instance. We no longer send state updates when it hasn't changed so if that is the case then this is working as designed

flexage commented 3 years ago

Sure!

In the logbook there's just one entry for that period:

Pixel 4 XL Last Notification changed to Your washing cycle has been completed
3:12:36 - 12 hours ago

The simple automation I'm using is as follows:

alias: Announce that a washing cycle is complete
description: ''
trigger:
  - platform: state
    entity_id: sensor.pixel_4_xl_last_notification
condition:
  - condition: state
    entity_id: sensor.pixel_4_xl_last_notification
    state: it.hoover.wizard
    attribute: package
action:
  - service: media_player.volume_set
    data:
      volume_level: '0.9'
    entity_id: media_player.living_room_nest_hub
  - service: tts.google_translate_say
    data:
      entity_id: media_player.living_room_nest_hub
      message: '{{ states(''sensor.pixel_4_xl_last_notification'') }}'
  - delay: '00:00:10'
  - service: media_player.volume_set
    data:
      volume_level: '0.5'
    entity_id: media_player.living_room_nest_hub
mode: single

It's essentially just using the state as a trigger, that has a condition which checks that the notification is coming from my washing machine app (to limit the scope of this automation in case I decide to add more automations based on other notifications in the future.

It then turns up the volume on the Google Home Hub, Announces via TTS and turns the volume back down.

(Also, sorry I've switched to my actual GitHub account - OP was made using a secondary account by mistake)

dshokouhi commented 3 years ago

Do you only get 1 type of notification? Maybe you can tell the app to send a "cycle started" notification if possible?

dshokouhi commented 3 years ago

If it always sends the same text then I am not sure how it works more than the first time.

flexage commented 3 years ago

It only has the one notification, it's not the best app...

One idea, If i adjusted my automation to clear the state of the Last Notification Sensor in HA, would the android app set it back when pushing the sensor states every now and then, or only when the sensor value actually changes on the phone?

dshokouhi commented 3 years ago

no the app keeps track of the last state that was sent to prevent us from sending data when we don't need to, the reason for that is because we were sending too many updates when we had nothing new to share so we decided to make a breaking change and only send updates when the state has changed.

flexage commented 3 years ago

That's pretty great news, so I can nuke the local state in HA, and then when the app pushes a new sensor state upon getting a notification, the state trigger should happen, thanks for the tip!

Out of curiosity, would HA detect the state had changed if the sensor had a state attribute with say a timestamp that the notification was received?

dshokouhi commented 3 years ago

I did not say that. The app does not send the same state more than once, meaning nothing gets sent if the state looks the same.

flexage commented 3 years ago

Oh, sorry, i didn't pick up the distinction. I thought we were talking about in-between payloads.

flexage commented 3 years ago

Regardless, thanks for your help and prompt responses. This information has been useful 👍 Please feel free to close this issue.

skynetua commented 3 years ago

@flexage I assume you specified only this washing app in sensor settings to report. The only workaround here for now is to track notifications for some other app as well. So sensor state will be changed periodically.

flexage commented 3 years ago

@skynetua you are indeed correct, and thanks for the tip. I have created a tasker task that runs on an interval, and creates a local notification every few minutes. I set the tasker notification to be silent, and minimised, so it is unobtrusive in the notifications tray. Obviously a bit of a hacky workaround, but works great for picking up the subsequent notifications from my washing machine 👍

dshokouhi commented 3 years ago

@flexage we have added a new sensor to alleviate the issue. The active notification count sensor in the latest beta will update and contain all active notification data for you along with post_time attribute for each notification. So as long as this count is changing you should be able to see the attributes updating as well. I am going to close this issue now since this sensor is in the beta and we are now providing as much notification data as we can. The google play store beta updates every Saturday however you are free to grab the APK off the github release page to get it sooner if you desire.

flexage commented 3 years ago

@dshokouhi Thank you for adding this, I will give it a try, it sounds like it will do the job nicely!

On a side note: It's great to see the amazing work that been done on the Android app, it wasn't long ago that we didn't have one and I had serious iOS envy. The android app is amazing and has so much going for it. Thank you again to you and all involved :+1: