Combining 2 Value_Templates

I have set up a RestAPI sensor that is pulling about 6 values, that i have converted into sensors. These all come back as “True” however I wanted them to display as “Yes” instead of True.

This is an example of what I have done to code this:

    pubsandrestuarants:
      friendly_name: Pubs and Restaurants Open?
      value_template: '{{ states.sensor.lockdown_update.attributes["pubsandrestuarants"] }}'
    pubsandrestuarants_yes:
        friendly_name: Pubs and Restaurants Open?
        value_template: >
          {% if is_state('sensor.pubsandrestuarants', 'True') %}
            Yes
          {% else %}
            No
          {% endif %}

This works fine but is there a more elegant way to combine both value_templates into just the one sensor?

why not use a binary sensor, with a opening device class and remove the ? from the title:

binary_sensor:
- platform: template
  sensors:
    pubsandrestuarants:
      friendly_name: Pubs and Restaurants
      device_class: opening
      value_template: "{{ state_attr('sensor.lockdown_update', 'pubsandrestuarants') }}"

Then the state under the hood would be ‘on’ or ‘off’ but in the UI it would be “Open” or “Closed”

1 Like

Haha interesting! Very clever. I’ll consider this.

I’m trying to learn more about templates, do you know if its possible to combine the two value templates into one or is that not possible?

No it’s not. Currently, there is no way to template a ‘translated’ state. You only get what’s in the value template.