How to tell if data_template variable is string or boolean true/false?

Hi, all-

Still learning about templates…

I want the value of assd_state in the data template below to be either boolean True or False, not a string “True” or “False”. The state attribute itself is, of course, a boolean.

Am I on the right track? Is there a simple way to know whether a variable is a string or boolean?

data_template:
  assd_state: "{{ state_attr('light.study', 'assumed_state') }}"

Thanks!

data_template:
  assd_state: >-
    {% if state_attr('light.study', 'assumed_state') == true %}
      True
    {% else %}
      False
    {% endif %}

It’s here

Cheers! Thanks for your answer and the tip.

Regarding my original question, I think that I may be looking in the wrong place for the source of the problem in my automation configuration.

I had originally tried an if statement to check the value of assumed stat, but I kept getting configuration validation errors. So, I decided to stop checking the value and just copy it into the variable as-is.

When I adapt your code, I am again getting config validation errors. There is a similar if statement in the same data_template which validates and executes correctly. Here is the relevant portion of the automation:

data_template:
  assumed_state:
    {% if state_attr('light.+trigger.topic.split('/')[1], 'assumed_state') == true %}
      True
    {% else %}
      False
    {% endif %}
  brightness: >
    {% if (state_attr('light.'+trigger.topic.split('/')[1], 'brightness'))|int >= 1 %}
      {{ (state_attr('light.'+trigger.topic.split('/')[1], 'brightness'))|int }}
    {% else %}
       255
    {% endif %}

This throws a configuration error:

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token ',', got 'assumed_state') for dictionary value @ data['action'][0]['data_template']['assumed_state']. Got None. (See /config/configuration.yaml, line 13). Please check the docs at https://home-assistant.io/components/automation/

The similar brightness if statement passes the config check and executes as expected.

I’m sure that I must be overlooking something simple. Any ideas?

Thanks!

Sure. Make sure that you have after assumed_state: exactly what you have after brightness:
It’s YAML, check that out

Thanks for the reply. I actually did have the > in the real config file. It was a cut and paste error getting it into the message. I checked again to be sure, and I’m still getting the error.

EDIT: Checked again as I was writing this and realized that I was missing a single quote in the in the assumed_state if statement.

Thanks again for taking a look.

yeah, it’s all about accuracy. even extra tab will make difference between pass and fail.
I’m Stil learning, too :wink: