How do I have a logical 'or' in a value_template 'if' comparison?

If I want to have a single mqtt binary_sensor triggered from two possible different data codes from the same remote door sensor (i.e. normal code, or the low battery code) what would the value_template syntax be ?

This below responds fine to the ‘normal’ code Data value 8A22DC, but I’d like the same bridge key 11 output to be triggered ON if the data is 8A22D0 or 8A22DC. Otherwise I have to create a wasteful extra sensor ID…

binary_sensor:
  - platform: mqtt
    name: "RF bridge key 11"
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data == '8A22DC' %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.rf_bridge_key_11') | upper}}
      {% endif %}
    off_delay: 3
    device_class: motion

I have no clue on coding in JSON unfortunately, anyone got an idea ?

Simply add an ‘or’.

{% if value_json.RfReceived.Data == '8A22DC' or value_json.RfReceived.Data == '8A22D0' %}

LOL, that easy. Thanks :slight_smile:

You could simplify a bit beyond that, too. E.g.:

binary_sensor:
  - platform: mqtt
    name: "RF bridge key 11"
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: >-
      {% if value_json.RfReceived.Data in ('8A22D0', '8A22DC') %}
        ON
      {% else %}
        {{states('binary_sensor.rf_bridge_key_11') | upper}}
      {% endif %}
    off_delay: 3
    device_class: motion

Interesting thanks.