[Solved] Template binary sensors - difference between YAML-created and GUI-created?

I’ve just started playing with HA, so bare with me.

I create a template binary sensor that uses the temp from our freeze. If the temp is above -15 degree Celsius the sensor should be on, else it should be off. It goes like this:

template:
  - trigger:
    # No triggers
  - binary_sensor:
      name: "Freeze2"
      state: "{{ (float(states('sensor.termometer_frys_nere_temperature'))) > -15  }}"

I can observe the sensor under Developer Tools → States and when the temperature changes to above -15, the state changes from off to on. So this is working fine.

I also wanted to try to create a binary sensor using the UI, so I created it using Helpers → Create Helper → Template → Template binary sensor

Initially, the dialog says “This template does not listen for any events and will not update automatically”

When I paste the same template as I use in YAML, the dialog updates to "This template listens for the following state change events:

  • Entity: sensor.termometer_frys_nere_temperature"

I press “Submit” and the binary sensor is added. I can look it up under Developer Tools → States and observe it.

But this sensor does not change when the temperature gets higher. I assumed that this sensor should work the same way as the one I created in YAML but obviously this is not the case. Or am I doing something wrong? Why is one sensor updating and the other one not? This page says that “Template entities will by default update as soon as any of the referenced data in the template updates”, but this does not seem to be the case here.
Please explain what is going on

Functionally they work the same way regardless of having been added through the GUI or yaml. Did you only paste the template section when defining it as a helper?

{{ (float(states('sensor.termometer_frys_nere_temperature'))) > -15 }}

Paste a screenshot of the helper creation page just before you press submit.

@odwide @Troon
Yes, I just used the same template text as in the YAML:

OK, that should turn on (state on, display “On”) when the temperature sensor goes above -15. Are you saying it does not?

If it doesn’t, please show a screenshot of the temperature sensor and template binary sensor plots at the change point. Like this:

That’s a Trigger-based Template Binary Sensor … but it has no trigger.

Without a trigger, it will never update.

EDIT

Never mind; I misread the configuration.

That’s what I thought at first, but it isn’t (unless I’m misunderstanding YAML again). The binary sensor is in a separate block.

1 Like

Doh! :man_facepalming:t3: You’re right; I missed that all-important leading hyphen.

Gosh. This is so embarrassing.
I took a look at a graph with temperature and the sensors, and suddenly the GUI sensor (FreezerDemo) updates just like the YAML one:

But my old, GUI-sensor (Freeze3), created two days ago, did not update. Had to take a look at its properties and suddenly I realized what was wrong:

"{{ (float(states('sensor.termometer_frys_nere_temperature'))) > -15  }}

I had missed that double quote at the beginning. After removing it, it works just as the other senors.
So I was all my mistake :frowning: Thanks for the help, guys

1 Like