Issue with template in binary sensor (I always see default values)

Hi,
i’m trying to use the “value_template” on a binary sensor (Nest thermostat) but i cannot see the custom value set by me.
In my configuration.yaml i’ve added this:

binary_sensor: !include_dir_merge_list binary_sensor

After this, in the folder “binary_sensor”, i’ve created a new yaml file with these lines:

- platform: template
  sensors:
    nest_thermostat_state:
      friendly_name: 'State'
      entity_id:
        - binary_sensor.entryway_thermostat_online
      value_template: >-
        {%- if is_state("binary_sensor.entryway_thermostat_online", "on") -%}
          Online
        {%- else -%}
          Offline
        {%- endif %}

Unfortunately, in my custom binary sensor binary_sensor.nest_thermostat_state I see the default values “on” and “off”. Why I cannot see the values “Online” or “Offline”?

Can you help me please? What i’m doing wrong?

Try single quotes in the value template:

{%- if is_state('binary_sensor.entryway_thermostat_online', 'on') -%}

Thanks for reply!
I tried to use single quotes in the value template but same result…

I’m using a similar scheme to rename some devices I track, but my formatting is a little different from yours:

-  platform: template
   sensors:
     epsonprinter:
       value_template: "{% if is_state('device_tracker.epson3e7694fiosrouterhome', 'home') %}on{% else %}off{% endif %}"

I don’t think you need the entity_id: lines.

This is my new code as suggest by you…but same result…I don’t understand!

- platform: template
  sensors:
    nest_thermostat_state:
      friendly_name: 'State'
      value_template: "{% if is_state('binary_sensor.entryway_thermostat_online', 'on') %}Online{% else %}Offline{% endif %}"

It could be how you did the include. What happens if you copy the value template and paste it into the template tester in the dev panel?

I tried to paste the template in the template tester and it’s works! The same condition return “Offline” in this case…

I tried with double quotes and single quotes…in the template tester it works but in my yaml doesn’t works!

Check to make sure your using the right include method then. I have a lot of trouble with figuring out which method is which myself.

I’ve added the template within the configuration.yaml but the result is the same…

binary_sensor:
  - platform: template
    sensors:
      nest_thermostat_state:
        friendly_name: 'State'
        value_template: "{% if is_state('binary_sensor.entryway_thermostat_online', 'on') %}Online{% else %}Offline{% endif %}"

It seems a bug…i don’t understand! I’m following the guide Template Binary Sensor but it seems doesn’t works very well…

If you are trying to change the output of the entity it would just be a template sensor.

or try using the elif… I think there was a post about using them both…

  mc_garage_state:
    value_template: '{% if is_state("binary_sensor.garage_controller", "on") %}Open{% elif states.binary_sensor.garage_controller, "off" %}Closed{% else %}Check Connection{% endif %}'

You’re right…with template sensor should works…but i want use “sensor_class” and other features provided by template binary sensor…why i can’t use it? I’m sad

I just tried with elif…but same result! :frowning:

Son of a!! Lol

Why do you want to use sensor_class:?

I would like use sensor_class because i want the icons provided by hass (better management of on/off states).
And I like the order!! :smiley:

But if there are not ant solutions…i will proceed with classic sensor templates…

Cool! You can change the icon using customize: though.

can i manage the yellow icons with customize and sensor template?

To be honest you should never have to look at your phone, tablet, or PC.

Best of Luck!

You can choose a single custom icon. That icon will change to yellow to indicate the on state.