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

Notifications do not come through when phone/app asleep #444

Closed xbmcnut closed 4 years ago

xbmcnut commented 4 years ago

Home Assistant Android version: 1.7.2-129 Android version: 10 Phone model: Nokia 7.1 Home Assistant version: 0.105.4 Last working Home Assistant release (if known):

Description of problem: Firstly, thank you so much for your time and effort in making the Android version. I’ve been using it from day one and it’s just got better and better. Great job! I do however have an issue with background notifications. It seems that I don’t get notifications when the app is asleep even though I have battery optimisation turned off. For reference, I also use the Synology Chat application for Home Assistant notifications and when testing persistent notifications this morning, the phone/watch combo sent me my doorbell notification from Synology Chat but the Home Assistant app did not until I opened the app then the notification came though straight away. Once awake, subsequent notifications are instant.

If I leave the phone off for an undetermined amount of time, notifications again stop until the phone/app is woken up.

I did have this issue with the Synology app too when I first configured it but by adding the Chat app to the battery optimisation bypass list fixed this but it does not make a difference with the Home Assistant app.

Traceback (if applicable):

Screenshot of problem:

Additional information: May be related to #420?

dshokouhi commented 4 years ago

Did you include ttl and priority in your service call? That is required for notifications to wake up a device in doze mode. You also want to make sure that background data is enabled and that battery optimizations are turned off for the app.

https://companion.home-assistant.io/docs/notifications/critical-notifications

xbmcnut commented 4 years ago

Thank you pointing that out! No I did not. Updating now to test. Thank you!

xbmcnut commented 4 years ago

So it this how I'd format it? What does the TTL flag do?

    action:
      - delay: 00:00:02
      - service: notify.mobile_app_nokia_7_1_app
        data:
          message: "The doorbell was pushed at {{ states.sensor.time.state }}"
          # title: "If not stated, it will say Home Assistant anyway"
          data:
            ttl: 0
            priority: high
            data:
              image: http://ha-ip-address:8123/local/images/front_porch.jpg
              actions:
                - action: "unlock_door" # The key you are sending for the event
                  title: "Unlock" # The button title            
                - action: "foyer_on" # The key you are sending for the event
                  title: "Foyer Lamp" # The button title
                - action: "siren_on" # The key you are sending for the event
                  title: "Police Siren" # The button title  
dshokouhi commented 4 years ago

drop the third data: and then move image and actions next to ttl and priority

ttl is part of the lifespan of the message...in order to wake the device it needs to be set to 0

https://firebase.google.com/docs/cloud-messaging/concept-options#ttl

xbmcnut commented 4 years ago

Thank you, appreciate that. So like this?

    action:
      - delay: 00:00:02
      - service: notify.mobile_app_nokia_7_1_app
        data:
          message: "The doorbell was pushed at {{ states.sensor.time.state }}"
          # title: "If not stated, it will say Home Assistant anyway"
          data:
            ttl: 0
            priority: high
            image: http://ha-ip-address:8123/local/images/front_porch.jpg
            actions:
              - action: "unlock_door" # The key you are sending for the event
                title: "Unlock" # The button title            
              - action: "foyer_on" # The key you are sending for the event
                title: "Foyer Lamp" # The button title
              - action: "siren_on" # The key you are sending for the event
                title: "Police Siren" # The button title
dshokouhi commented 4 years ago

Yup just like that.

Closing as duplicate of #153 please comment in that issue in case you still experience issues with the delay

xbmcnut commented 4 years ago

Awesome. Thanks for the prompt reply and help.