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 Notification not working with template #44094

Closed
mythicaleinhorn opened this issue Dec 7, 2020 · 13 comments
Closed

Chronometer Notification not working with template #44094

mythicaleinhorn opened this issue Dec 7, 2020 · 13 comments

Comments

@mythicaleinhorn
Copy link
Contributor

Home Assistant Android version: beta-527-84e6a24-full

Android version: 11

Phone model: Google Pixel 3a

Home Assistant version: 0.118.5

Last working Home Assistant release (if known):

Description of problem: When using a template to get a timestamp for the chronometer when option for a notification, it doesn't render the template, resulting in the chronometer not showing up in the notification.
When the same template is rendered beforehand using the template dev-tool and the timestamp is entered directly for the when option, so when no template is used, it works without any problems.

Traceback (if applicable): n/a


Screenshot of problem:

Additional information: The ISS example from the documentation doesn't work either.

@dshokouhi
Copy link
Member

Can you please share the yaml that you tried?

@member68
Copy link

member68 commented Dec 7, 2020

I'm running into the same issue. Here's my info and some yaml to reproduce.

Home Assistant Android version: 3.0.2-full

Android version: 8

Phone model: LG V30

Home Assistant version: 0.118.5

This code needs a running timer called "timer.normalwasche".

message: >-
  "Wäsche fertig um {{ (as_timestamp(state_attr('timer.normalwasche', 'finishes_at'))) | timestamp_custom('%X') }}"
data:
  channel: alarm_stream
  tts: 0
  priority: high
  chronometer: true
  when: "{{ as_timestamp(state_attr('timer.normalwasche', 'finishes_at')) | int }}"

Steps to reproduce:

  1. Template Editor with code from above:
    image

  2. Calling the service with the template editor output on the right
    image

  3. Notification with chronometer is shown
    image

  4. Calling the service with the template editor input on the left
    image

  5. Notfication without chronometer is shown
    image

@mythicaleinhorn
Copy link
Contributor Author

I didn't have time yet to copy my exact setup, hopefully tomorrow, but the bug shows up in the same way for me.
Everything is rendering out perfectly fine in the template tool but in the real notification, only the template for the notification message is working but for the chronometer it isn't.

So I conclude the following is probably happening:
Before the notification is sent to the app the title and message are checked for templates and get rendered out to text if there are any. The when parameter for the chronometer on the other hand is send as is, thus getting discarded because it isn't a valid UNIX timestamp.

@dshokouhi
Copy link
Member

I didn't have time yet to copy my exact setup, hopefully tomorrow, but the bug shows up in the same way for me.
Everything is rendering out perfectly fine in the template tool but in the real notification, only the template for the notification message is working but for the chronometer it isn't.

So I conclude the following is probably happening:
Before the notification is sent to the app the title and message are checked for templates and get rendered out to text if there are any. The when parameter for the chronometer on the other hand is send as is, thus getting discarded because it isn't a valid UNIX timestamp.

Don't just guess, go to app configuration then notification history and look at the data that the app received. That will show the exact data that we got for the notification itself.

@mythicaleinhorn
Copy link
Contributor Author

I didn't know that feature existed, sorry!
I used the example provided by @member68 in this case.

when the template is used as value
Screenshot_20201208-230915.png

when the timestamp is used directly
Screenshot_20201208-230959.png

@dshokouhi
Copy link
Member

We may need to move this issue to HA core as it seems anything under the additional data element is not having the template rendered before being sent out. I suspect iOS has a similar issue too and possibly other notify platforms.

@mythicaleinhorn
Copy link
Contributor Author

Can you transfer this issue or is it best to create a new one in core?

@dshokouhi
Copy link
Member

I am unable to transfer it but I have requested the core team to move it so we can wait a bit for someone to take a look

@dzamlo
Copy link

dzamlo commented Jan 7, 2021

This bug only exist in the developer tool. When used in an automation, the template is rendered as expected.

@mythicaleinhorn
Copy link
Contributor Author

I did some more testing and I think I found the culprit.

I tried using

  when: "{{ as_timestamp('states.binary_sensor.some_sensor.last_changed') | round }}"

What I didn't notice was the as_timestamp() function erroring out because of the ', which I haven't noticed because this doesn't get logged and instead just silently dropped.
It was only when I tried to add another int to the timestamp in the automation, that I finally saw the error in the logs.

Traceback

Logger: homeassistant.components.automation.neue_automatisierung_2
Source: helpers/service.py:190
Integration: Automatisierung (documentation, issues)
First occurred: 0:54:44 (2 occurrences)
Last logged: 0:54:44

Neue Automatisierung: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
While executing automation automation.neue_automatisierung_2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 188, in async_prepare_call_from_config
    service_data.update(template.render_complex(config[conf], variables))
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 93, in render_complex
    return {
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 94, in <dictcomp>
    render_complex(key, variables): render_complex(item, variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 93, in render_complex
    return {
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 94, in <dictcomp>
    render_complex(key, variables): render_complex(item, variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 98, in render_complex
    return value.async_render(variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 355, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 436, in _async_call_service_step
    domain, service_name, service_data = service.async_prepare_call_from_config(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 190, in async_prepare_call_from_config
    raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' 
  when: "{{ as_timestamp(states.binary_sensor.some_sensor.last_changed) | round }}"

(the exact same as above but without the surrounding ') works flawlessly in an automation.

@eddiezane
Copy link

This bug only exist in the developer tool. When used in an automation, the template is rendered as expected.

This helped me find what was going on.

Potential fix here #46436.

@eddiezane
Copy link

Sounds like the fact that message and title are working with templates inside the developer tools is unintentional.

This is probably safe to close.

#46436 (comment)

@github-actions
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 13, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants