Template gives error in config.yaml

Hello,

i’m trying to work with templats, what i want is do a count on my door and window contacts.

when i check the template in the template editor, it is working, but when pasting the code to the config.yaml. it won;t load.

what do i do wrong ?

sensors:
  - platform: template 
    sensors:
      contact_count:
        entity_id: sensor.count
        value_template: > 
          {% set binary_sensor = [
            states.binary_sensor.voordeur,
            states.binary_sensor.achterdeur,
            states.binary_sensor.raam_voor,
            states.binary_sensor.raam_achter,
            ] %}
          {{ binary_sensor | selectattr('state','eq','on') | list | count }}

When you run Configuration Check, what is the error message produced?

You do have an entity called sensor.count?

I have found the solution, i need to delete

entity_id: sensor.count

from my sensor, after that it worked, and i have a new sensor in my entities, i came to this with the post from francis.

Why did you originally include this line in the configuration?

entity_id: sensor.count

I have the impression you do not understand the purpose of including/excluding this line so here’s how it works:

What it instructs Home Assistant to do is to monitor sensor.count for changes to its state. When its state does change, the value_template is evaluated and sensor.contact_count is updated.

If sensor.count doesn’t change state or rarely changes state (or doesn’t even exist), then sensor.contact_count is never, or rarely, ever updated.

By removing entity_id: sensor.count it makes Home Assistant (on startup) inspect the contents of value_template and identify all the entities it contains. It will then monitor all of these entities for state-changes. That means it will monitor the binary_sensors you have listed in the value_template.

1 Like

Thanks for the info, now i know why it work like it works now.

Where can i find that info, the documentation isn’t realy clear about that.

Review the Template documentation, specifically this section: EntityIDs