Help with a response_variable and then using in a value_template

Ok, spending too much time on this and need some more eyes for what I am missing.

I get a response_variable back from my script. It’s successfully returning a value like [“Christmas”, “Red”, “100”] as I wish.

  • service: script.scr_holiday
    data: {}
    response_variable: WhatHoliday

I then successfully adjust the color of the RGB on my chandelier by the holiday, this case to “Red”. This is working PERFECT!!!

  • service: light.turn_on
    target:
    entity_id: light.gfoyer_chandelier
    data:
    brightness_pct: 10
    color_name: “{{ WhatHoliday.value[1] }}”

Then I want to use the “{{ WhatHoliday.value[0] }}”. Just to prove to me it get the value i expect I create a log entry and it too is successful, returning ‘Christmas’.

  • service: logbook.log
    data:
    name: “*** Test Function Event ***”
    message: “==> The Holiday is {{ WhatHoliday.value[0] }} <==”

NOW my issue. I want to do an IF or CONDITION, that if {{ WhatHoliday.value[0] }} == ‘Christmas’ … Do something. I can not for the life of me get the value_template (or anything else) to ever evaluate correctly. I thought it be as simple as (or some variation of (ive tried many))… I even tried some thing with States but never any luck. Its got to be something simple and stupid that i am missing.

  • if:
    • condition: template
      {{ WhatHoliday.value[0] == ‘Christmas’ }}
      then:

Any help on what I am missing?

Thank You in Advance!
David

  - if:
      - condition: template
        value_template: "{{ WhatHoliday.value[0] == 'Christmas' }}"
    then:

Reference

Template Condition


You can also use shorthand notation:

  - if: "{{ WhatHoliday.value[0] == 'Christmas' }}"
    then:

Thank You!!! Works PERFECT now. I would have bet that I tried that but I clearly did not. I think i had that condition in there all the time.

Thank You again!!!

I am having a similar problem and have tried many different formats. I just can’t seem to figure out how to use the IF statement to evaluate the response_variable. Any assistance would be greatly appreciated.
I realize it would be easy to set this up with a simple automation of the state for each garage door, however, I am wanting to understand this process so I can eventually do more actions depending on the number of garage doors and which door is open. I think this is my first step getting there.

image

There should not be a hyphen in front of then: or else:… and endif is not a valid key at all.

The appropriate way to setup a If/Then action in YAML is demonstrated in the docs.

Keep in mind that the script returning the response could also be configured improperly, but you have not shared that, so we have no way of knowing…

Also, please follow Community Guidlines #11 & 14 and post properly formatted code instead of screenshots of code.

YAML for Non-Programmers