#Passing boolean to a script from an automation and evaluating it

1 messages · Page 1 of 1 (latest)

mystic spire
#

Hello,

What I am trying to do is to have an automation, which calls a script, while passing a couple of variables to said script. In the script I need to evaluate one of the boolean variables to true, before proceeding. I'm having trouble writing the template to properly do this evaluation, as it always ends up being false.

The automation is:

alias: Test Messaging
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.office
conditions: []
actions:
  - action: script.announcement_duplicate
    data:
      message: This is a test message
      urgent: "true"
mode: single

And the corresponding script is below. Don't pay attention to the action. I'm concerned with getting the IF statement evaluated properly at this point.

sequence:
  - if:
      - condition: template
        value_template: "{{ is_state(urgent, \"true\") }}"
    then:
      - data:
          volume_level: 0.3
        target:
          entity_id:
            - media_player.garage_speaker
        enabled: true
        action: media_player.volume_set
      - parallel:
          - data:
              entity_id: media_player.garage_speaker
              message: "{{ message }}"
            enabled: true
            action: tts.cloud_say
          - data:
              entity_id: media_player.garage_speaker
              message: This is an "{{urgent}}" urgent
            enabled: true
            action: tts.cloud_say
alias: Announcement (Duplicate)
mode: queued
max: 20
description: ""

Thank you!

digital kiln
#

You are passing the string "true" not the boolean value true

#

And you can't use is_state() like that

#

Just use "{{ urgent == 'true' }}"

#

And if you would actually pass a boolean value (so without the quotes) you could just use

value_template: "{{ urgent }}"
mystic spire
#

Ooooh. Easier than I thought! Thank you so much. Let me give it a try.