#Why do booleans do not act as booleans?

1 messages · Page 1 of 1 (latest)

cobalt ermine
#

Suppose you trigger is:

  - trigger: state
    entity_id: input_boolean.my_boolean
    from: on
    to: off

Sort of True/False, and applies to binary_sensors and more objects. Also applies to the state of conditions.
This way of defining it returns an error. The state of the trigger must be a string.
It is correct to use quotes (single or double).

Why doesn't HA use real booleans in such cases? I can use numbers without quotes but I don't understand why every thing else is a string.

slate pine
#

these files are YAML files, so it's not a HA thing.

Older YAML standards specified to use strings for booleans and supported "true"/"false", "on"/"off" or "yes"/"no" (single or double quotes)

Newer YAML standards added true/false without quotes, so you could try that. it should be more future-proof.

cobalt ermine
#

I'm reading why this change. Apparently, and you're correct, yaml used to interpret those values all as booleans.
But that (somehow) led to confusion. Ambiguity... Strings like on would be a boolean.
So, since 2009 (or yaml 1.2), the only real boolean is true|false.

This behavior confuses me more honestly. I generally tend to think as string anything that's inside quotes.

Thank you for your answer tho!

slate pine
#

it's kind of the same in python if you read input without typecasting it to a string. i had a program fail on me because the dev hadn't done that and asked for 2 letter country code. the code for norway is NO which immediately was converted to a boolean and chrashed the program 😄

cobalt ermine
#

Oh damn 😆 You gotta cast it yoself directly on the page! smart