Binary Sensor from Dryer power not working

Hello,
I am trying to make a binary sensor from my sensor.dryer_power. I built it from a combo of suggestion on the forum but for the life of me I can get this one right.
Would greatly appreciate any help, thanks.

I’m getting this error:

Invalid config for [binary_sensor.template]: invalid template (TemplateSyntaxError: Encountered unknown tag ‘else’.) for dictionary value @ data[‘sensors’][‘dryer_status’][‘value_template’]. Got “{{ states(‘sensor.dryer_power’)|float > 100 }} Drying {%- else %} Off {%- endif %}” invalid template (TemplateSyntaxError: unexpected ‘}’) for dictionary value @ data[‘sensors’][‘dryer_status’][‘icon_template’]. Got “{% if states(‘sensor.dryer_power’) | float > 100 }}\n mdi:tumble-dryer\n{%- else -%}\n mdi:tumble-dryer-off\n{%- endif %}”

For this in my binary_sensors.yaml

- platform: template
  sensors:
    dryer_status:
      friendly_name: "Dryer"
      delay_on:
        minutes: 1
      delay_off:
        minutes: 1
      value_template: >-
        {{ states('sensor.dryer_power')|float > 100 }} 
        Drying 
        {%- else %} 
        Off 
        {%- endif %}
      icon_template: >-
        {% if states('sensor.dryer_power') | float > 100 }}
          mdi:tumble-dryer
        {%- else -%}
          mdi:tumble-dryer-off
        {%- endif %}

Binary sensors are on or off. Not “Drying’, not 'Off” (capital letter). Also your if/else template format is invalid (no if, only else).

Try this:

- platform: template
  sensors:
    dryer_status:
      friendly_name: "Dryer"
      delay_on:
        minutes: 1
      delay_off:
        minutes: 1
      value_template: >-
        {{ states('sensor.dryer_power')|float > 100 }} 
      icon_template: >-
        {% if states('sensor.dryer_power') | float > 100 }}
          mdi:tumble-dryer
        {%- else -%}
          mdi:tumble-dryer-off
        {%- endif %}

If you want a sensor that has states Drying and Off, use a sensor rather than a binary sensor. Also be sure to quote the word ‘Off’ or it will be interpreted as a boolean.

1 Like

Wow, ok. Very helpful thank you. For some reason, it’s so hard to wrap my brain around YAML. Thank you for taking the time.

So if I want a Dryer sensor that reports two states, “Drying” and “off” should I add something to my “sensor.dryer_power” that currently is in my sensor.yaml as:

dryer_power:

      friendly_name: Dryer Power

      value_template: “{{ states.switch.dryer.attributes.current_power_w }}”

Or should I do something with this Binary sensor when I get it to work?

The error I am getting with that code @tom_I in binary_sesonrs.yaml is:

TemplateSyntaxError: unexpected ‘}’

      icon_template: >-
        {% if states('sensor.dryer_power') | float > 100 }}

Should be

      icon_template: >-
        {% if states('sensor.dryer_power') | float > 100 %}

That worked. No errors. But even though “sensor.dryer_power” current state is 188, “binary_sensor.dryer_status” shows as off. Damn this is frustrating.