Thank you very much, that did the trick.
Check the link again and copy the code at it. For some reason, the forums changed the link when I originally posted. I just reverted the post back to its original edit.
Perfect, Thank you!
Thank you works perfectly and I got to learn something new about templating.
Hi guys, I need your help again. Were do I need to place (default=0) in template below?
{% set trash = as_timestamp(strptime(state_attr(“sensor.afval_rest”,“date”), “%Y-%m-%d”)) | timestamp_custom("%d-%m") %}
take a look at this post and see if you can figure it out.
Thanks Petro, issue resolved.
Hey @123 its all working well for me but I see these error messages regarding the template:
[homeassistant.helpers.event] Error while processing template: Template("{{ not is_state('sensor.sm_g986b_next_alarm') }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 397, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1604, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, 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 1734, in wrapper
return func(hass, *args[1:], **kwargs)
TypeError: is_state() missing 1 required positional argument: 'state'
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 513, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 399, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: is_state() missing 1 required positional argument: 'state'
2021-10-19 16:16:53 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('TypeError: is_state() missing 1 required positional argument: 'state'') while processing template 'Template("{{ not is_state('sensor.sm_g986b_next_alarm') }}")' for attribute '_attr_available' in entity 'sensor.minutes_next_alarm_ahmed'
I haven’t come across these errors before, can you help please?
I can help but you don’t appear to be reading the error message but simply reaching out to me to read it for you. The answer to the problem is explained within the error message.
TemplateError(‘TypeError: is_state() missing 1 required positional argument: ‘state’’) while processing template ‘Template(“{{ not is_state(‘sensor.sm_g986b_next_alarm’) }}”)’ for attribute ‘_attr_available’ in entity 'sensor.minutes_next_alarm_ahmed
If you look at the documentation for the is_state
function you will see it requires two arguments but you have only supplied one argument (that’s exactly what the error message said). You have used the is_state
function incorrectly and must also supply the state
argument (again, that’s what the error message said).
thanks for pointing out. I suppose I would have to use the is_state
as any other doesn’t work for me in my case which means that I will have those error messages every time.
What is the goal and which functions have you tried to achieve your goal?
the goal is to get the alarm in minutes so that I can trigger an automation (for the future of course). I am getting the alarm in minutes from my previous template and your modified one which works fine. My only concern was the build up of errors in my log.
I tried to use states(...
instead of is_state
but it doesnt work…
If that’s the goal then you are going about it the wrong way. However, this discussion is now completely off-topic because it no longer has anything to do with the recent changes concerning default values.
you asked for the goal mate but thanks for your help
Because I was trying to help you but needed to know if the discussion still involved default values. It’s clearly not so I won’t be pursuing it and would appreciate if you don’t tag me again in the future. Thank you for your understanding and good luck.
Hi @petro,
Except from the issues last night, I noticed the DST are one day too late.
next:
spring: '2022-03-28 02:00:00+02:00'
fall: '2021-11-01 02:00:00+02:00'
event: '2021-11-01 02:00:00+02:00'
days_to_event: 1
phrase: gain an hour
friendly_name: Daylight Savings Times
device_class: timestamp
I think it should be:
spring: ‘2022-03-27 02:00:00+02:00’
fall: ‘2021-10-31 02:00:00+02:00’
Or do I miss something?
It works for me in my timezone. You have to update the template for your timezone. You have to set the correct hour that the change occurs.
EDIT: for my timezone, its 2. For your timezone, it’s 14:05? which is an odd time, anyways for it to work you need to put in a time past 14:05, i.e. 15. So previous should change from 2 to 15 in the template.
Updated the template so you don’t need to specify a time
As always, help really appreciated.
Hello guys,
Need help suppressing this warning. Tried to figure out myself using this link from above, but failing.
error:
Template warning: 'strptime' got invalid input '2021-08-27T00:13:16.555' when rendering template '{{ 91 - (( as_timestamp(now()) - as_timestamp(strptime(states.sensor.vj_ssl_cert_issued.state, "%Y-%m-%d")) )/ (3600*24)) | round(0) }}' but no default was specified. Currently 'strptime' will return '2021-08-27T00:13:16.555', however this template will fail to render in Home Assistant core 2022.1
code in question:
value_template: '{{ 91 - (( as_timestamp(now()) - as_timestamp(strptime(states.sensor.vj_ssl_cert_issued.state, "%Y-%m-%d")) )/ (3600*24)) | round(0) }}'