Template sensor not created

Any idea why the following template sensor doesn’t populate?

template:
  - sensor:
      - name: "Cloud Sensors"
        state: >
          {{ states.binary_sensor | selectattr( 'state', '==', 'on' ) | selectattr( 'attributes.icon', '==', 'mdi:cloud' ) | list | length }}

icons don’t exist on every binary sensor, you’d need to check to make sure it exists.

{{ states.binary_sensor | selectattr( 'state', '==', 'on' ) | selectattr('attributes.icon', 'defined') | selectattr( 'attributes.icon', '==', 'mdi:cloud' ) | list | length }}

It does, there is actually 22.

Result type: number

21

I don’t get your comment, either way the template I produced will return the result you’re looking for while accounting for binary sensors that do not have the icon attribute.

It was just in response to

My template in the template editor shows 22 which is what I was trying to show you, and a pic of the actual sensor with it’s attributes.

I didn’t realize you posted a changed template, I assumed it was the same.

Using your template doesn’t produce the sensor either.

template:
  - sensor:
      - name: "Cloud Sensors"
        state: >
          {{ states.binary_sensor | selectattr( 'state', '==', 'on' ) | selectattr('attributes.icon', 'defined') | selectattr( 'attributes.icon', '==', 'mdi:cloud' ) | list | length }}

image

Do you have 2 template sections?

It’s in a package as all my other template sensor configs.

Should be working as long as you don’t have 2 template sections in 1 file.

Also, you have to have the new template style somewhere in your config. Otherwise you have to restart if you just added it.

I don’t, the config posted above is all that’s in that particular package.

I do, in other packages, like below with over 20 sensors.

template:
  - sensor:
      - name: Large Tank Temperature
        unit_of_measurement: "°F"
        device_class: temperature
        state: "{{ '%+.1f'|format(state_attr('climate.itc_308_wifi_thermostat', 'current_temperature')) }}"

image

Then it should be showing up. The syntax is correct. There’s nothing wrong with the syntax, so I’d look towards your packages. Also, you could always restart instead of reload.

the other possibility is that it’s not named cloud_sensors

Sorting by friendly name or state doesn’t show anything either.

Ok, then something is wrong with how you set that package up.

Precisely, rookie mistake :man_facepalming:, wasn’t named with “.yaml”

Thank you, much appreciated.

image