Use of Boolean Field in Scripts

I am trying to get a boolean to work in my script to choose between two notification actions. The condition in the IF Statement always returns false no matter how I configure it. Choose/Default yield the same result. Please take a look at the code below and tell me what I am doing wrong. I am brand new to HA.

alias: Send Message to iPhone
fields:
  title:
    selector:
      text: null
    name: Title
    description: Add the Message Title
    required: true
  message:
    selector:
      text: null
    name: Message
    description: Add the Message
    required: true
  critical_notification:
    selector:
      boolean: {}
    name: Critical Notification?
    description: Is this a critical notification?
    default: true
sequence:
  - if:
      - condition: template
        value_template: |
          {{ is_state("critical_notification", "on") }}
    then:
      - service: notify.mobile_app_ iphone
        data:
          title: "{{ title }} "
          message: "{{ message }} "
          data:
            push:
              sound:
                name: default
                critical: 1
                volume: 1
    else:
      - service: notify.mobile_app_iphone
        data:
          title: "{{ title }} "
          message: "{{ message }} "
mode: single

Change this:

{{ is_state("critical_notification", "on") }}

To this:

{{ is_state(critical_notification, "on") }}

Without the double-quotes it’s the name of a script variable. With them it’s a string.

I had also tried that and it was also returning false.

On closer inspection, I now see that critical_notification is a Boolean Selector. In other words, it doesn’t contain the entity_id of an Input Boolean but simply a true or false boolean value (not on/off). In that case, you can’t use is_state() because that’s exclusively for testing the state of an entity. A Boolean Selector isn’t an entity.

  - if:
      - condition: template
        value_template: "{{ critical_notification }}"
    then:

Perfect! That worked. Thanks for the explanation.

1 Like