Template warning, but how to solve?

because of some higher required log level this afternoon, I see:

Sensor sensor.marijn_location_picture has device class None, state class None and unit Marijn thus indicating it has a numeric value; however, it has the non-numeric value: home (<class 'str'>)

now, which is probably there for some time, but want noticed before.

I have no idea why HA thinks it should expect a numeric value.

template:

  - sensor:

      - unique_id: marijn_location_picture
        unit_of_measurement: Marijn
        <<: &location_pic
          name: >
            {% set id = this.attributes.get('id') %}
            {{states('person.' ~ id)|title|replace('_',' ')}}
          state: >
            {% set id = this.attributes.get('id') %}
            {% set state = states('person.' ~ id) %}
            {{state|slugify}}
          picture: >
            {% set id = this.attributes.get('id') %}
            {% set state = states('person.' ~ id) %}
            {% if state in ['home','not_home'] %}
              /local/family/{{id}}_{{state|slugify}}.png
            {% else %}
            {{states('sensor.' ~ id ~ '_overlay_image')}}
            {% endif %}

and customized the id with:

homeassistant:

  customize:

    sensor.marijn_location_picture:
      id: marijn

would appreciate a suggestion here, is this a bug in HA, a user error, or?

only thing I could think of is the

unit_of_measurement: Marijn

which I use for the sake of displaying that with a badge bar below it, is seen as a number. should I maybe quote that?

there is another odd one:

      - unique_id: wind_compass
        state: >
          {{states('sensor.buienradar_wind_direction_azimuth')}}
        name: >
          {{states('sensor.wind_compass_abbreviation')}}
        unit_of_measurement: °
        picture: >
          {%- set degrees = states('sensor.buienradar_wind_direction_azimuth')|float(0) %}
          {%- set path = '/local/weather/wind_compass/' %}
          {%- set ext = '.png' %}
          {%- set num = ((degrees // 11.25) * 11.25 // 1)|int %}
          {%- set num  = 0 if num  == 360 else num %}
          {{'{}{}{}'.format(path,num,ext)}}

also complaining it has no classes set.

Sensor sensor.wind_compass has device class None, state class None and unit ° thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class 'str'>);

cant we have numeric entities without setting a class? or , rephrase, shouldnt we?

Both problems are caused by using unit_of_measurement then not specifying a number (or getting an unknown in the second case). It’s not complaining about the classes, just bundling a lot of information into the same error message.

It’s not a bug, it’s complaining about you hijacking unit_of_measurement for display purposes.

thanks.

I did find a few others too that do that and yes are not numbers. before I had log_level error, and had to lower to info and now see these…

hehe. yes. needed that for some configs in the past. will revisit those.

the degree is a bit odd though. it has a perfectly fine value, and, since templates are almost at the end of the startup, cant see that faulting in to a unknown. will guard it nevertheless

thanks

I think this is why - unit_of_measurement implies a numeric value.

Try removing it and reloading your template sensors.