Help with template in automation with MQTT trigger

Hi there -

I can’t quite work out what is going wrong with the template in the automation below. I’m trying to pass either “on” or “off” as power_state to a rest_command.

The MQTT trigger payload is either Online or Offline.

If I hardcode power_state to either on or off, the rest_command executes correctly.

- alias: Light Status Master Bedroom
  trigger:
    platform: mqtt
    topic: light_status_master_bedroom/tele_ls/LWT
  action:
    service: rest_command.light_status_updater
    data:
      endpoint: "master_bedroom"
    data_template:
      power_state: >
        {% if trigger.payload.strip() == 'Online' %}
          'on'
        {% else %}
          'off'
        {% endif %}

Any ideas?

Thanks,
Ron

Got it working. The key appears to be insuring that trigger.payload and “Online” are compared as strings. Working code:

- alias: Light Status Master Bedroom
  trigger:
    platform: mqtt
    topic: light_status_master_bedroom/tele_ls/LWT
  action:
    service: rest_command.light_status_updater
    data_template:
      endpoint: master_bedroom
      power_state: >-
        {% if trigger.payload|string == "Online" %}
          on
        {% else %}
          off
        {% endif %}