I’ve come to an odd case:
i have installed HOLIDAY component and i set up an additional NEXT HOLIDAY sensor. This sensor has attribute “today_is_holiday” which is normally false, except when it’s holiday, then it’s true.
Here comes my odd situation: i included this attribute in automation under condition, so it doesn’t trigger when it’s holiday. I set up automation in visual interface, not direct yaml code:
selected “state”
selected sensor.next_holiday
selected atrribute “today_is_holiday”
entered false in state field.
But it never trigerred. When i looked timeline error was
result: false state: false
wanted_state: 'false'
So i looked yaml code, it was:
condition:
- condition: state
entity_id: sensor.next_holiday
state: 'false'
attribute: today_is_holiday
Then i manually removed quotes and automation WORKS:
condition:
- condition: state
entity_id: sensor.next_holiday
state: false
attribute: today_is_holiday
But, then of course visual editor complains that it’s not correct code for visual editor:
The provided value for 'state' is not supported by the visual editor. We support (string) but received (false)
I noticed that some of my automations do have quotes, some don’t … Where’s the catch?
This depends on the data type you are trying to provide.
Quotes are usually strings (text). So “5” would be a text, not a number.
And “state” VS state (without quotes) would be a text VS an ENUM (I think).
Exceptions for this within home assistant are templates.
“{{ 3 + 4 }}” e.g. returns a number.
For this I find it very helpful to completely clear the templates Debug console and then paste my template in there - so I always know, which datatype it returns.
Entity attributes can be other types (string, number, boolean, etc…)
Beware of this trap:
The template editor interprets the result of the template. Templates themselves dont do this.
So in the template editor your example returns the number 8, but if that template was used as a value_template for a template sensor, it would return the string "8".
I have complained about this before, but apparently it is expected behaviour.
Aha…
Many thanks for explanation. I’m aware of string-number difference, so in my case it’s, as it seems, that used attribute is taken as number by HA… possibly original state is 0 and 1 and not “true” and “false”… i’ll dig into this some more. I have to find where in database attribute values are saved and check out type…
You’re correct. And, it may be a solution: if i choose “numeric state” instead of “state” and i set condition to "below ‘1’ it seems to work (at least when i tried to imitate holiday). Further testing will show… (tomorrow we have a holiday)
Thanks!
That would be confusing. Just dont quote the boolean false or it becomes the string "false".
The opposite goes for the strings "on" and "off". You don’t want them being interpreted as the booleans on or off in trigger or condition states. States are strings.