I am trying to add below wait template for a automation to wait until hvac system becomes idle (as it already reached set temperature) or wait for another binary sensor to be off for 10 minutes. For some reason it never seems to trigger completion once the 10 min is reach for the other sensor state being off. When I try the template in Dev Tools, it seems to return true when hvac_action is idle but if its anything other than that, it returns error “ValueError: Template error: as_timestamp got invalid input ‘’ when rendering template ‘{{ (state_attr(‘climate.my_ecobee’, ‘hvac_action’) in [‘heat’]) or (as_timestamp(now()) - as_timestamp(states.binary_sensor.defrost.last_changed) > 600) }}’ but no default was specified”. Any ideas what I am doing wrong or how to clean up the template syntax?
{{ (state_attr('climate.my_ecobee', 'hvac_action') in ['idle']) or (states('binary_sensor.heat_pump_defrost_detector') in ['off'] and (as_timestamp(now()) - as_timestamp(states.binary_sensor.defrost.last_changed)) > 600) }}
Then try to check in Dev tools only this template:
as_timestamp(now()) - as_timestamp(states.binary_sensor.defrost.last_changed)
Just a speculation - this sensor could become “unknown” …
Also, for less confusing yourself and others, suggest you to present your long expressing as
{{
(
state_attr('climate.my_ecobee', 'hvac_action') in ['idle']
) or
(
states('binary_sensor.heat_pump_defrost_detector') in ['off'] and
(
as_timestamp(now()) - as_timestamp(states.binary_sensor.defrost.last_changed)
) > 600
)
}}
and ALWAYS post a code in triple backquotes.
1 Like
Tried just the portion and that part seems fine.
Means - if the whole expression is tested in Dev tools - you got this error if hvac_action is not idle, right?
And this error is persistent (not erratic), right?
Then probably same error should be displayed when only that small snippet is tested in Dev tools and hvac_action is not idle.
The below works fine in dev tool whether its idle or not.
{{state_attr('climate.my_ecobee', 'hvac_action') in ['idle']}}
And what about a long expression?
You can check either your variant from the 1st post - or my structured from here.
Results with error:
ValueError: Template error: as_timestamp got invalid input ‘’ when rendering template ‘{{ ( state_attr(‘climate.my_ecobee’, ‘hvac_action’) in [‘idle’] ) or ( states(‘binary_sensor.heat_pump_defrost_detector’) in [‘off’] and ( as_timestamp(now()) - as_timestamp(states.binary_sensor.defrost.last_changed) ) > 600 ) }}’ but no default was specified
And this error comes permanently when “not idle”?
How this “binary_sensor.defrost” was created? Is it a template sensor?
dont want to barge in here, but that template is not very useful, checking if the attribute is in a list of 1 element
why not check the state of the attr directly:
{{is_state_attr('climate.my_ecobee','hvac_action','idle')}}
(it wont change the outcome, but it’s easier to read and more succinct imho)
ofc the same goes for
states('binary_sensor.heat_pump_defrost_detector') in ['off']
which should be
{{is_state('binary_sensor.heat_pump_defrost_detector','off')}}
as for the time comparison, did you try this format:
{{now() - states.binary_sensor.defrost.last_changed > timedelta(seconds=600)}}
?
or on a trigger template with something like:
- >
{{now() - this.attributes.last_triggered > timedelta(minutes=1) if
this.attributes.last_triggered is not none else true}}
, because it could be not yet triggered and then would return false
binary_sensor.defrost is a trend sensor that monitors rate of supply air temperature dropping.
Can it be unknown or unavailable?
According to log, you got an error while accessing “states.binary_sensor.defrost.last_changed”.
I think i got it working using below at least in dev tools, will test in automation to make sure works as expected:
{{ (state_attr('climate.my_ecobee', 'hvac_action') in ['idle']) or
(states('binary_sensor.heat_pump_defrost_detector') in ['off'] and
(as_timestamp(now()) - as_timestamp(states.binary_sensor.heat_pump_defrost_detector.last_changed)) > 600) }}