core
core copied to clipboard
Islamic Prayer Times issue with the sensor integration after Core update - does not support platform setup
The problem
Hi HA community,
after I update the system to the recent version the slamic Prayer Times sensor stop working. it seems the new update time template is not compatiable with the integration. see below log
Logger: homeassistant.components.template.trigger Source: components/template/trigger.py:60 Integration: template (documentation, issues) First occurred: 11:22:39 PM (17 occurrences) Last logged: 11:22:39 PM
Error initializing 'template' trigger for 'Sunrise': ValueError: Template error: strptime got invalid input '2022-06-07T09:42:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.sunrise_time"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
Error initializing 'template' trigger for 'Duher reminder': ValueError: Template error: strptime got invalid input '2022-06-07T17:21:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S")) -600 }}' but no default was specified
Error initializing 'template' trigger for 'Asr reminder': ValueError: Template error: strptime got invalid input '2022-06-07T21:26:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S")) -600 }}' but no default was specified
Error initializing 'template' trigger for 'Magrib reminder': ValueError: Template error: strptime got invalid input '2022-06-08T01:00:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")) -600 }}' but no default was specified
Error initializing 'template' trigger for 'Isha reminder': ValueError: Template error: strptime got invalid input '2022-06-08T02:48:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S")) -600 }}' but no default was specified
What version of Home Assistant Core has the issue?
Home Assistant Core 2022.6.4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Islamic Prayer Times
Link to integration documentation on our website
https://www.home-assistant.io/integrations/islamic_prayer_times/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Error evaluating 'template' trigger for 'Sunrise': ValueError: Template error: strptime got invalid input '2022-06-07T09:42:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.sunrise_time"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
11:22:41 PM – (WARNING) template - message first occurred at 11:22:41 PM and shows up 17 times
Error while processing template: Template("{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.sunrise_time"), "%Y-%m-%dT%H:%M:%S")) }}")
11:22:39 PM – (ERROR) helpers/template.py - message first occurred at 11:22:39 PM and shows up 17 times
Error initializing 'template' trigger for 'Sunrise': ValueError: Template error: strptime got invalid input '2022-06-07T09:42:00+00:00' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.sunrise_time"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
11:22:39 PM – (WARNING) template - message first occurred at 11:22:39 PM and shows up 17 times
The islamic_prayer_times platform for the sensor integration does not support platform setup. Please remove it from your config.
11:22:22 PM – (ERROR) Sensor
2022-06-07 23:22:22 ERROR (MainThread) [homeassistant.components.sensor] The islamic_prayer_times platform for the sensor integration does not support platform setup. Please remove it from your config.
2022-06-07 23:22:39 WARNING (MainThread) [homeassistant.components.template.trigger] Error initializing 'template' trigger for 'Adhan': ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_times_fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
2022-06-07 23:22:39 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_times_fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1546, in strptime
return datetime.strptime(string, fmt)
File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/local/lib/python3.9/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data 'unknown' does not match format '%Y-%m-%dT%H:%M:%S'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 409, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1842, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1549, in strptime
raise_no_default("strptime", string)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1331, in raise_no_default
raise ValueError(
ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_times_fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 525, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 411, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.islamic_prayer_times_fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}' but no default was specified
Additional information
No response
template documentation template source (message by IssueLinks)
islamic_prayer_times documentation islamic_prayer_times source (message by IssueLinks)
Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Hey there @engrbm87, mind taking a look at this issue as it has been labeled with an integration (islamic_prayer_times
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Looking at the template you are using I think you can change it to something like "{{ as_timestamp(states("sensor.sunrise_time")) }}" which will give you the timestamp directly. Also if you are comparing it to current time you can directly use " {{ as_timestamp(now()) }}. You also need to make sure the sensors have a valid state as the error log indicates that the state was 'unknown' when the error happened.
Instead of a Template Trigger, use a Time Trigger. The sensor's time format is ideal for use in a Time Trigger.
trigger:
- platform: time
at: sensor.dhuhr_prayer
Th
Looking at the template you are using I think you can change it to something like "{{ as_timestamp(states("sensor.sunrise_time")) }}" which will give you the timestamp directly. Also if you are comparing it to current time you can directly use " {{ as_timestamp(now()) }}. You also need to make sure the sensors have a valid state as the error log indicates that the state was 'unknown' when the error happened.
Thanks @engrbm87 @tdejneka , I tried both fix but it didnt work. If look at the log the problem with time format I think the python verson in Home assistant got updated and the new version didn't like the time format. (time data 'unknown' does not match format '%Y-%m-%dT%H:%M:%S')
can i change the python version ?
hello all, I have exactly the same issue, if someone can give us the solution :) thank you
I tried both fix but it didnt work
Then you're doing something wrong because this issue has nothing to do with python version. I tested what I suggested and it does work.
Regarding this:
(time data 'unknown' does not match format '%Y-%m-%dT%H:%M:%S')
It received a time value of unknown
. I don't know what you did to make it produce that value but it will definitely fail to be converted by strptime
. Possibly because you don't have an entity named sensor.time_date
yet it's referenced in your template.
if someone can give us the solution
Two solutions have been posted. Which one did you try?
I believe this Issue isn't due to a bug in the Islamic Prayer integration or with any bug in the Jinja2 template processor. This is simply due to the use of outdated templates for processing the sensor values produced by the integration. This belongs as a question in the community forum, not as a bug report here on GitHub.
Instead of a Template Trigger, use a Time Trigger. The sensor's time format is ideal for use in a Time Trigger.
trigger: - platform: time at: sensor.dhuhr_prayer
Thanks @tdejneka , it worked now i was do it wrong. but i have question now. I have another automation that uses the prayer time sensor but it will trigger 15 min before the time occur and it will play mp3 file to remind us that the prayer time is near.
with platform: time at: *** i only can use delay. how i can use the opposite ?
hello all, I have exactly the same issue, if someone can give us the solution :) thank you
I will tackel the prayer reminder issue and share with you the full code
@CRCbary
The question about how to offset the prayer time has been already been asked by others, and answered, in the community forum.
https://community.home-assistant.io/t/offset-time/319009/2?u=123
Instead of a Template Trigger, use a Time Trigger. The sensor's time format is ideal for use in a Time Trigger.
trigger: - platform: time at: sensor.dhuhr_prayer
Hi tdejneka, Can you post the whole time trigger for all the prayer times? Thanks in advance
hello thank you for your response I did the same with the sensor, and it's Work, as you told it, the issue is coming from the template, not from Islamic prayer plugin thank you very much for your help, I appreciate have a nice day
Can you post the whole time trigger for all the prayer times?
There's an example in the community forum:
https://community.home-assistant.io/t/azaan-adhan-azan-on-your-alexa-devices/312543/2?u=123
Automation.yaml file extract for Adan using Platform as Time instead of Template - This fixed my issue as well. Thank you.
Automation.yaml file
alias: Adan description: Automation for Dhuhr, Asr, Maghrib, and Isha Adan trigger:
- platform: time at: sensor.dhuhr_prayer
- platform: time at: sensor.salah_asr
- platform: time at: sensor.salah_maghrib
- platform: time at: sensor.salah_isha condition: [] action:
- data: media_content_id: https://dummyurl.com/local/Adan.mp3 media_content_type: MUSIC service: media_extractor.play_media target: entity_id: media_player.googlenesthub1 mode: single
If you want the configuration.yaml file then here it is as well
Sensors in configuration.yaml file
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'time_date'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
- platform: template sensors: salah_fajr: friendly_name: "Fajr" value_template: "{{ (as_timestamp(states('sensor.fajr_prayer')) - 60) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp salah_dhuhr: friendly_name: "Dhuhr" value_template: "{{ (as_timestamp(states('sensor.dhuhr_prayer')) - 60) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp salah_asr: friendly_name: "Asr" value_template: "{{ (as_timestamp(states('sensor.asr_prayer')) - 60) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp salah_maghrib: friendly_name: "Maghrib" value_template: "{{ (as_timestamp(states('sensor.maghrib_prayer')) + 180) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp salah_isha: friendly_name: "Isha" value_template: "{{ (as_timestamp(states('sensor.isha_prayer')) - 60) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp salah_sunrise: friendly_name: "Sunrise" value_template: "{{ (as_timestamp(states('sensor.sunrise_time')) - 60) | timestamp_custom('%Y-%m-%dT%H:%M:%S+00:00', false) }}" device_class: timestamp
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.
@home-assistant close
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.