home-assistant / android

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

Display notification on top of other notifications #3208

Open felipecrs opened 1 year ago

felipecrs commented 1 year ago

Is your feature request related to a problem? Please describe.

I'm trying to create a notification like Doorbell is ringing. I'm currently using:

clickAction: /lovelace/video-porteiro
group: video-porteiro-chamando
tag: video-porteiro-chamando
channel: Video Porteiro
importance: high
priority: high
ttl: 0
vibrationPattern: 1000, 100, 1000, 100, 1000, 100
persistent: true
timeout: 120
visibility: public
image: /api/camera_proxy/camera.video_porteiro
actions:
  - action: URI
    title: Atender
    uri: /lovelace/default_view?call=888
  - action: IGNORE
    title: Ignorar

But this causes the notification to be displayed on the middle of my other notifications of other apps like WhatsApp and Telegram.

Describe the solution you'd like

Some way to make the notification be displayed on the top of the list. Maybe some sort of Call flagging can be used for the purpose?

Describe alternatives you've considered, if any

I did not find any.

Additional context

None.

dshokouhi commented 1 year ago

I believe this will require the app to set the notification as a conversation. The app may also need to identify as such and I am not sure we will qualify for that.

https://developer.android.com/develop/ui/views/notifications/conversations

felipecrs commented 1 year ago

With https://www.home-assistant.io/integrations/conversation/ this may actually make sense!

dshokouhi commented 1 year ago

that conversation has nothing to do with a notification you are trying to create :) Android actually only wants a messaging/calling app which the HA app is not. You can read more about that in the link above, but its not at all related to the HA integration.

jpelgrom commented 1 year ago

I think ongoing notifications are also usually at the top of the panel (think: navigation), which is used by the app when sending a notification with persistent: true. Which device are you using as you've alreayd included it in your code?

I believe this will require the app to set the notification as a conversation.

Forcing notifications in a conversation template doesn't sound great.

felipecrs commented 1 year ago

It indeed have nothing to do with my use case, although Doorbell ringing is the same as Doorbell calling, which by itself could well be categorized as a call much like any other calling app like Telegram.

I wonder if the Tuya/Smart Life app is also identified as a calling app, because doorbell do calls through their app too.

My point about the Conversation Hass integration is that someone could indeed use the Android conversation features for notifications to make a real "chat-bot" using the Home Assistant app.

felipecrs commented 1 year ago

Which device are you using as you've alreayd included it in your code?

Tested with both S20 FE Android 12 (which includes Samsung "optimizations") and a Mi 9 with Pixel Experience Android 12 (which does not include any OEM "optimizations").

I will record an example.

felipecrs commented 1 year ago

I just noticed that it momentarily displays at the top when it rings.

https://user-images.githubusercontent.com/29582865/211644145-421df99b-0268-4271-884a-dbfd44f34bb5.mp4

dshokouhi commented 1 year ago

I think ongoing notifications are also usually at the top of the panel (think: navigation), which is used by the app when sending a notification with persistent: true. Which device are you using as you've alreayd included it in your code?

I have some ongoing notifications that are lower in priority than a Ring missed person or even a discord message.

I think maybe we need to allow users to set the category?

https://developer.android.com/reference/android/app/Notification.Builder#setCategory(java.lang.String)

For example maybe this category will tell the system to keep it at the top? https://developer.android.com/reference/android/app/Notification#CATEGORY_CALL

although this may still not qualify to be above a conversaton it could help because I dont think google maps navigation uses conversation style notifications?

felipecrs commented 1 year ago

That sounds great.

Apart from that, something that I noticed is that the notification does not display expanded (i.e. with the buttons showing for quick reaction). I suppose this is a consequence of not being on the top of the notification list though.

dshokouhi commented 1 year ago

Apart from that, something that I noticed is that the notification does not display expanded (i.e. with the buttons showing for quick reaction). I suppose this is a consequence of not being on the top of the notification list though.

this behavior will vary from device to device, typically the first notification will be expanded. I believe some devices has an option to keep it expanded but not all. Default behavior is keep them collapsed, the app has no control over this.

felipecrs commented 1 year ago

Got it.

dshokouhi commented 1 year ago

one thing I am not certain about is how reliable setting the category will be

May be used by the system for ranking and filtering. "may be used" tells me there are no guarantees.

https://developer.android.com/reference/android/app/Notification#category

felipecrs commented 1 year ago

I'd say this deserves a shot! :D

dshokouhi commented 1 year ago

Did some tests using call and navigation with and without persistent: true the notification did not appear above the conversation notifications like discord. With that said I can send a junk string as well and the notification is fine but I wonder what the point is if it doesn't do anything?

I am not sure if we will be able to get into the Conversation area without meeting the requirements and I am not sure we will be able to meet the requirements.

https://developer.android.com/develop/ui/views/notifications/conversations#api-notifications

felipecrs commented 1 year ago

Have you tried CATEGORY_MISSED_CALL?

To ensure that missed calls are surfaced in the prioritized conversation shade and appear correctly in the conversion widget, format missed call notifications as conversations with a category set to CATEGORY_MISSED_CALL.

https://developer.android.com/develop/ui/views/notifications/conversations#api-notifications:~:text=To%20ensure%20that%20missed%20calls%20are%20surfaced%20in%20the%20prioritized%20conversation%20shade%20and%20appear%20correctly%20in%20the%20conversion%20widget%2C%20format%20missed%20call%20notifications%20as%20conversations%20with%20a%20category%20set%20to%20CATEGORY_MISSED_CALL.

dshokouhi commented 1 year ago

yup tried missed_call as well.

format missed call notifications as conversations

This the part where it was mentioned earlier that we should not do

felipecrs commented 1 year ago

Right. That's the missing part. I'll dive deeper into the documentation later to understand these requirements.

felipecrs commented 1 year ago

I don't have a Nest Hello doorbell, but I bet their app displays doorbell notifications on top. 😅

I just hope that's not because they are Google. But since I can't confirm, this worths nothing.

dshokouhi commented 1 year ago

They could indeed get their notification to show up if they meet the requirements, which they probably do.

Heres a break down of the requirements

A notification is considered as a conversation notification if the following is true:

This we do not do today

  • (Only if the app targets Android 11 or higher) The notification is associated with a valid long-lived dynamic or cached sharing shortcut. The notification can set this association by calling setShortcutId() or setShortcutInfo(). If the app targets Android 10 or lower, the notification doesn't have to be associated with a shortcut, as discussed in the fallback options section.

this we also do not do and its asking us to link the notification to a shortcut on the device.

  • The user hasn't demoted the conversation from the conversation section via notification channel settings, at the time of posting.

out of the apps control

felipecrs commented 1 year ago

Thank you. That makes it easier to follow.

Checking the documentation I'd say that there is another option which makes much more sense to my use case: CallStyle notifications.

There is even support for some kind of native Answer and Hang-up button which is... great, as I have actions for both. Incoming, Ongoing, my automations has enough data to fill these events as well.

Home Assistant is already a place for real calls by using the hass-sip-card and many people use it already. Not only that, go2rtc provides 2-way audio communication which is probably going to make its way to a Lovelace card as well.

That's to say that, if the companion app could expose the ability of handling CallStyle notifications to Home Assistant, that would be a lot for people to build on. I certainly would build on it. :)

dshokouhi commented 1 year ago

Checking the documentation I'd say that there is another option which makes much more sense to my use case: CallStyle notifications.

I am not sure where you got it from that this will work for a conversation as the requirements explicitly mention which style to use and its only MessagingStyle. I don't even see CallStyle mentioned on the linked page.

Home Assistant is already a place for real calls by using the hass-sip-card and many people use it already. Not only that, go2rtc provides 2-way audio communication which is probably going to make its way to a Lovelace card as well.

Sorry but we should not create features for custom integrations/cards, we could consider this if it were part of HA core

felipecrs commented 1 year ago

From here (clickable image):

image

Sorry but we should not create features for custom integrations/cards, we could consider this if it were part of HA core

Giving the ability of creating Call-like notifications does not necessarily mean people has to use custom integrations. The majority of the existing official doorbell integrations (like Nest) provides events for when a doorbell rings. That's enough for people to be able to leverage Call-like notifications, for example.