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

WearOS: Add option to refresh template tile when in view #4007

Closed jeremysherriff closed 8 months ago

jeremysherriff commented 11 months ago

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

My Template tile is usually out of date when I scroll to it. Existing refresh interval options for template tiles are quite coarse, but making them more aggressive could be a bad thing (battery life, data usage etc)

Describe the solution you'd like

Add a new command_ notification that triggers a refresh of the template tile. As well as (or instead of) setting a refresh interval for my template tile, I could then refresh it using an automation that leverages the existing notification channel. This will allow for pseudo-real time updates of the template tile, without using a high refresh interval. It would be similar to the request_location_update command notification, in that the update is not guaranteed and frequent calls may be detrimental to battery life. See the warnings here.

Describe alternatives you've considered, if any

Additional context

If this feature may complicate or be complicated by #3697

dshokouhi commented 11 months ago

I don't think this is possible outside of the app as all we can set is the freshness interval which is user controlled here. Have you tried moving the template tile to be closer to the watchface so it updates faster? My camera tile closest to the watchface is always up to date but not the ones next to it.

dshokouhi commented 11 months ago

Regarding the refresh intervals. Data usage shouldn't be of any concern for a template tile is only text. For battery only you can see if changing the interval will be detrimental, depending on your usage it may not be. I have the interactive sensor enabled on my watch so a network call gets made anytime my screen turns on and my battery life is not impacted by that.

jeremysherriff commented 11 months ago

Thanks for the thoughts.

My specific use case is a template tile that shows the state of my garage door. I have this because my garage door remote often doesn't trigger, and sometimes when I think I've closed the door I find that it is still open when I check (via HA).

In my use-case, a 5-minute refresh interval is too aggressive for most of the time, but when the garage does actually open/close I would like the template tile to almost-immediately reflect the state. A 1-minute interval is massively over-aggressive when there is likely to be only 4 or 6 state changes across the course of any 24 hour period. I am looking for a way to trigger the template tile refresh when the state of the door changes.

Another potential option is for the template tile to trigger a refresh automatically on coming into view - would that be an option? It would seem sensible that many/most users would want the template tile to be up-to-date upon scrolling onto it. If indeed this is possible, this "on visible" update could either be an optional addition to the refresh interval (eg a tick-box), or could be part of the refresh interval selection list, like this:

dshokouhi commented 11 months ago

unfortunately you'll never be able to get the template tile to reflect the state of the entity, lots of discussion about keeping tiles up to date here

Also adding an option for "On viewing tile" won't work as the app doesnt get notified about that. Tiles are meant to be limited and cant be kept as up to date as HA users would like.

Alternatively you should consider adding the entity as a entity state complication, complications update anytime the screen turns on because they are allowed to, that sounds like a better fit for your use case.

https://companion.home-assistant.io/docs/wear-os/#complications

dshokouhi commented 11 months ago

Also adding an option for "On viewing tile" won't work as the app doesnt get notified about that.

ok I stand corrected, after speaking with @jpelgrom we have found that there is a way we can possibly update the tile when in view but we need to test and see how things work.

https://developer.android.com/reference/kotlin/androidx/wear/tiles/TileService?hl=en#onTileEnterEvent(androidx.wear.tiles.EventBuilders.TileEnterEvent)

If this works I personally don't think it should be included as part of the refresh interval but we should update the tiles by default when in view

jpelgrom commented 11 months ago

If this works I personally don't think it should be included as part of the refresh interval but we should update the tiles by default when in view

Unless you set the refresh interval to never, in which case it wouldn't make sense for it to automatically refresh when viewed

dshokouhi commented 11 months ago

If this works I personally don't think it should be included as part of the refresh interval but we should update the tiles by default when in view

Unless you set the refresh interval to never, in which case it wouldn't make sense for it to automatically refresh when viewed

ah yes good point, Manual should indeed remain a manual :)

So with that logic then we should probably also add an option to only update when viewed? I can see that being useful too, why have a tile update if you are not looking at it, then again not using a freshness interval will result in slower updates šŸ¤”

jeremysherriff commented 11 months ago

This is sounding really good, not sure about the difficulty to code such a feature but from my point of view it meets my needs and seems a logical improvement of the overall Template Tile functionality.

ah yes good point, Manual should indeed remain a manual :)

So with that logic then we should probably also add an option to only update when viewed? I can see that being useful too, why have a tile update if you are not looking at it, then again not using a freshness interval will result in slower updates šŸ¤”

My proposed list of refresh intervals above sounds like it meets that:

  • Manual
  • On viewing tile
  • 1 minute
  • 2 minutes
  • 5 minutes
  • 10 minutes
  • etc

So just to confirm, the outcome of choosing "15 minutes" would be a background refresh every 15 minutes, plus a "foreground" refresh when the Tile is scrolled into view?

dshokouhi commented 11 months ago

So just to confirm, the outcome of choosing "15 minutes" would be a background refresh every 15 minutes, plus a "foreground" refresh when the Tile is scrolled into view?

yes thats how it should work however I think each watch is going to have slightly different behavior. Official docs on this interval

Take this for example my Pixel Watch has 3 camera tiles all to the left of the watchface all 3 have the same 1 hour refresh interval selected.

Just about every time I go to the first camera tile to the left its always up to date unless I check more in the hour. The second tile has a 50% chance of being up to date or updating when I scroll into view. The third tile usually updates a few seconds after scrolling into view but sometimes I need to hit the manual refresh button if i feel its taking too long. Now how old can the image be you might wonder? it can be HOURS it can be night time and I see a photo from the morning or vice versa so its definitely not updating as you would expect.

My template tile is 3 tiles over to the right, usually out of date but updates as soon as I scroll into view. I have the template tile refresh interval also set to 1 hour.

So IMO the delayed update when tile is scrolled into view will probably have the same effect in my own use case as the watch is probably delayed in updating until the screen comes on when a freshness interval has lapsed. Whats most interesting is that the first tile fully respects the interval while the others wait until its in view.

jeremysherriff commented 11 months ago

Interesting background information. I typed out a long response musing about different angles of it, but that would send the conversation off topic šŸ˜„

I had a quick search of the Wear tile code and don't see the onTileEnterEvent event being employed for the camera tiles. Maybe that could help "solve" that difference in observed behaviour?

dshokouhi commented 11 months ago

I had a quick search of the Wear tile code and don't see the onTileEnterEvent event being employed for the camera tiles. Maybe that could help "solve" that difference in observed behaviour?

we don't use this event in any of our tiles, camera tile and template tile have the same logic here actually and in my experience I see the same behavior. The watch controls when things are updated according to the refresh interval. Adding this event will only increase the frequency in updates when the tile is scrolled into view, it won't mean the tile will be kept more up to date when not in view.

Set your freshness interval to 1 minute and you will probably see the same delays mentioned, tile will appear out of date momentarily then without any interaction it will update.