If then else not working

I have a simple if-then-else, which is evaluating a calendar trigger in an automation.
Somehow the trigger works but not the if/then/else loop afterwards

here is a snippet from the conditions in the choose loop:

      - conditions:
          - condition: trigger
            id: HASS Calendar
          - condition: state
            entity_id: input_boolean.vacation_mode
            state: "off"
          - condition: template
            value_template: "{{ 'coffee' in trigger.calendar_event.summary }}"
        sequence:
          - if:
              - condition: template
                value_template: "{{ 'coffee-on' in trigger.calendar_event.summary }}"
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.coffee
            else:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id: switch.coffee

The IF condition is evaluated but it returns false, even though the calendar summary was ‘coffee-on’.
So today morning I woke up to “manual coffee” :rofl:

Any suggestion?

Post the full automation, look at the traces and show the state of the calendar.

Maybe also check for capitalisation of coffee in the calendar.

Post the Trace json… but to @jchh 's point:

condition: template
value_template: "{{ trigger.calendar_event.summary is search('coffee', ignorecase=1) }}"
1 Like

Okay, I learned how t use the JSON trace log to debug automations/
I found that event summary was actually ‘coffee’ not ‘coffee-on’ as needed.

Cockpit error of course. :face_with_hand_over_mouth:
Thanks for all the hints and suggestions.

If that’s the case then how does Didgeridrew’s suggestion solve “If then else not working”?

The suggested template:

condition: template
value_template: "{{ trigger.calendar_event.summary is search('coffee', ignorecase=1) }}"

is functionally identical to what you already had here:

condition: template
value_template: "{{ 'coffee' in trigger.calendar_event.summary }}"

All it adds is case insensitivity but that’s not required in this situation because your ‘coffee’ string is already in lowercase. Even if the string was not in lowercase, your existing template can be easily enhanced to this:

condition: template
value_template: "{{ 'coffee' in trigger.calendar_event.summary | lower }}"