Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chronometer fails if parameter 'when' is given a float #5024

Closed
harmpter opened this issue Jan 30, 2025 · 4 comments · Fixed by #5036
Closed

Chronometer fails if parameter 'when' is given a float #5024

harmpter opened this issue Jan 30, 2025 · 4 comments · Fixed by #5036
Labels
bug Something isn't working notifications

Comments

@harmpter
Copy link

Home Assistant Android app version(s):
2025.1.2

Android version(s):
14

Device model(s):
Google Pixel 5

Home Assistant version:
2025.1.4

Last working Home Assistant release (if known):

Description of problem, include YAML if issue is related to notifications:
Chronometer fails if parameter when: is given a float. The notification still posts, but without chronometer.

action: notify.mobile_app_dd
data:
  message: test
  data:
    chronometer: true
    when: "{{ now()|as_timestamp }}"

Companion App Logs:


Screenshot or video of problem:

Additional information:
Probably irrelevant, but a float ending in .0 like 1738267025.0 seems to pass as an integer and results in a working chronometer timeout.

I hope this issue can help fill a to-do list with many many checked items and make someone feel very productive 🚀😄

@harmpter harmpter added the bug Something isn't working label Jan 30, 2025
@dshokouhi
Copy link
Member

@harmpter
Copy link
Author

harmpter commented Jan 30, 2025

I think rather than updating the docs, casting to an integer would make more sense and be way more convenient for the user. Or is that not as easy as I think? It would make sense because now().timestamp() returns a float and that's what is most likely used there.

EDIT: I checked the logs but did not see it. But I'm not too worried, I'm only appending the logs in case they are useful to you.

01-30 21:36:05.519 29083 14147 W FirebaseMessaging: Unable to log event: analytics library is missing
01-30 21:36:05.519 29083 14147 D FCMService: From: <<>>
01-30 21:36:05.520 29083 29083 D MessagingService: Creating notification with following data: {when=1738269365.193415, webhook_id=<<>>, message=test, chronometer=true, server_id=3}
01-30 21:36:05.523 29083 29083 D MessagingService: Show notification with tag "null" and id "-1192389361"
01-30 21:36:08.282 29083 29083 I ImeTracker: io.homeassistant.companion.android:a683856e: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT
01-30 21:36:09.476 29083 10064 D LogcatReader: Read logcat for pid 29083

@dshokouhi
Copy link
Member

sorry a long is actually expected here which is why our conversion reverts to 0 if it is unable to convert to a long value at that point we dont set up the chronometer at all: https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder?hl=en#setWhen(long)

you should be able to cast to int in your template to fix this today, personally i use {{ as_timestamp(now()) | int }} in my automations that use a chronometer

@harmpter
Copy link
Author

Okay this makes sense, and thank you for the fix, that's what I'm using too. I was just thinking it could make sense to have it accept a float too. If it isn't the easy quick fix as I imagined then we can of course close this issue. And thanks for your fast replies :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working notifications
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants