Command Line Sensor Device Class error?

I’ve been using a command line sensor to track my server temperature. It’s pretty darn close to the example in the documentation. Noticed a new error in my log:

Entity sensor.server_temp (<class ‘homeassistant.components.command_line.sensor.CommandSensor’>) with device_class None reports a temperature in °C which will be converted to °F. Temperature conversion for entities without correct device_class is deprecated and will be removed from Home Assistant Core 2022.3. Please update your configuration if device_class is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub

Sensor config:

sensor:
  - platform: command_line
    name: Server Temp
    command: 'cat /sys/class/hwmon/hwmon0/temp1_input'
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'

I didn’t see anywhere in the documentation to declare a device class or that it’s even a valid flag. Setting via customization doesn’t make the error go away. Anyone else seen this?

1 Like

Customize is the way to do it. What did you set the device class to?

Should be:

sensor.server_temp:
  device_class: measurement

Reloading the core should be all that is required but it wont update the sensor customization until the sensor state updates. A restart will update the sensor as soon as home assistant restarts.

That is what I took from the docs as well. I had set the device class to temperature, since that is available. Changed to measurement and restart but same error. Sensor does show class of measurement now. Below is the entire yaml package.

homeassistant:
  customize:        
    sensor.server_temp:
      device_class: measurement

logbook:
  exclude:
    entities:
      - sensor.uptime

sensor:
  - platform: command_line
    name: Server Temp
    command: 'cat /sys/class/hwmon/hwmon0/temp1_input'
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'

  - platform: systemmonitor
    resources:
      - type: last_boot
      - type: disk_use_percent
        arg: /
      - type: memory_use_percent
      - type: processor_use

  - platform: template
    sensors: 
      uptime:
        friendly_name: 'Since Last Boot'
        #entity_id: sensor.time
        value_template: >
          {% set up_time = as_timestamp(now()) - as_timestamp(states('sensor.last_boot')) %}

          {% set minutes = (up_time // 60) | int %}
          {% set hours = (minutes // 60) %}
          {% set days = (hours // 24) %}
          {% set weeks = (days // 7) %}

          {% set minutes = (minutes % 60) %}
          {% set hours =  (hours % 24) %}
          {% set days = (days % 7) %}

          {% macro phrase(value, name) %}
                    {%- set value = value %}
                    {%- set end = 's' if value > 1 else '' %}
                    {{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
          {%- endmacro %}
                    
          {% set text = [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min') ] | select('!=','') | list | join(', ') %}
          {% set last_comma = text.rfind(',') %}
          {% if last_comma != -1 %}
            {% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
          {% endif %}
          
          {{ text }}

System Health for reference:

version: core-2021.9.5
installation_type: Home Assistant Container
dev: false
hassio: false
docker: true
user: root
virtualenv: false
python_version: 3.9.6
os_name: Linux
os_version: 5.10.28-Unraid
arch: x86_64

I have the same issue with a SQL sensor.
This is how I did it.

  customize_glob:
    sensor.outdoor_temperature:    
      device_class: measurement

I tried both temperature and measurement for the device_class but the warning persists.
In developer the device_class is showing the value I have set it to.

Any ideas?

Thank you

1 Like

Me too…

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:282
Integration: Sensor (documentation, issues)
First occurred: 5:43:26 AM (1 occurrences)
Last logged: 5:43:26 AM

Entity sensor.cpu_temperature (<class 'homeassistant.components.command_line.sensor.CommandSensor'>) with device_class None reports a temperature in °C which will be converted to °F. Temperature conversion for entities without correct device_class is deprecated and will be removed from Home Assistant Core 2022.3. Please update your configuration if device_class is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+command_line%22

Same issue here for OpenHardwareMonitor…

openhardwaremonitor warnings about temperature units · Issue #56256 · home-assistant/core (github.com)

1 Like

Has anyone found a solution to this? My guess is that the sensor doesn’t have a unique ID for the temperature. Looking at the attributes, it’s not listed.

image
image

Although I tried all suggestions above in customize.yaml, without any luck.

Did any of you create the bug reports requested in the error/warning?

There was an issue opened on github for OpenHardwareMonitor on 9/15/21, but I dont think it included bug reports?