If float cannot convert the supplied value to a number, it will report the default value.
If no default value is provided and it cannot convert the value, the template fails with an error.
In the following example, if float cannot convert the sensor’s value to a number, it will report 0 so the test becomes 0 > 100. Without a default value, the template would simply fail.
In the following example, if float can’t convert the sensor’s value (because it’s unavailable or unknown) it will report 20. You can set the default value to be whatever number is the best choice for your application.
thanks to fix my code however that part is working… what donesn’t work is the part related the variables which always said “not passed” but with gray color… nor organge as usually… so i guess something doesn’t work here or something related the variable setup.
- condition: template
value_template: >
{{ temp > temperature_target or (humidity not in ['unknown',
'unavailable', 'None'] and humidity | float > humidity_target) }}
Where are you seeing these colors and “not passed” message? In the Automation Editor? Don’t use that for testing Template Conditions, especially when they contain variables defined outside of the actual template.
No, because it only evaluates the template, not any other part of your automation, like the variables section. So it doesn’t know what temp or temperature_target or humidity are because they are defined outside of the template.
Here’s a simple example:
alias: example 123456
trigger:
- platform: state
entity_id: sensor.foo
action:
- variables:
x: 1
y: 2
- choose:
- conditions:
- condition: template
value_template: "{{ x + y == 3 }}"
sequence:
- service: notify.persistent_notification
data:
title: Test
message: "{{ x }}, {{ y }}"
default: []
The Template Condition “Did Not Pass” because the variables x and y are defined outside of the template and the Automation Editor only evaluates what is known in the template.
You’re not the only person who has been misled by the way the Automation Editor tests Template Conditions. Ideally it should process the variables section but it doesn’t. It limits its processing to Jinja2 code in the template and excludes processing any YAML (like what is defined in the variables section).
I suppose what would be a little bit better is if it posted an error message when it encounters a problem with the template (such as "found undefined variables: temp, humidity, …) like what is shown in the Template Editor.