Template Sensor - String Based on Power Value

Hi All,

I’m trying to create a Multi-Line Template Sensor based on the value of the current power of a power monitoring socket.

I can get a Binary sensor to work like this:

- binary_sensor:
    - name: "Hot Water Heating"
      device_class: heat
      state: >       
        {{ states('sensor.hotwater_energy_power')|float > 15 }}

Works fine. But next step is i want to get multiple strings for that value and eventually change the icon depending on the value. I just can’t seem to get it, and cant find the documentation to show how to do what i consider a simple task.

Here’s what i have:

- sensor:
    - name: "How Water Status"
      state: >
          {% if is_state('switch.hot_water_load_sensor', 'off') %}
            off
          {% elif is_state('sensor.hotwater_energy_power')|float < 15) %}
            standby
          {% elif is_state('sensor.hotwater_energy_power')|float > 15) %}
            heating
          {% else %}
            failed
          {% endif %}

I’m sure its something simple.

Worked it out. I finally worked out how to use the template editor in developer tools. Very Good Indeed.

Here’s the complete template that i ended up with:

- sensor:
    - name: "Hot Water Status"
      state: >
          {% if is_state('switch.hot_water_load_sensor', 'off') %}
            off
          {% elif states('sensor.hotwater_energy_power')| float < 15.0 %}
            standby
          {% elif states('sensor.hotwater_energy_power')| float > 15.0 %}
            heating
          {% else %}
            failed
          {% endif %}
      icon: >
          {% if is_state('switch.hot_water_load_sensor', 'off') %}
            mdi:power-plug-off-outline
          {% elif states('sensor.hotwater_energy_power')| float < 15.0 %}
            mdi:fire-off 
          {% elif states('sensor.hotwater_energy_power')| float > 15.0 %}
            mdi:fire
          {% else %}
            mdi:fire-alert
          {% endif %}