"class 'XXXXX', state class 'None' unit 'YYY' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)"

I have reviewed and cleaned as much as I can given my knowledge a bunch of sensors that I am collecting from several Awair devices via its local API, but errors related to “the non-numeric class” is really overwhelming and I fail to understand what is lacking or needs to be corrected.

Any hints or pointers are highly appreciated.

Code:

- platform: rest
  name: awair_master_bedroom
  scan_interval: 60
  resource: 'http://192.168.xx.xxx/air-data/latest'
  json_attributes:
    - timestamp
    - score
    - dew_point
    - temp
    - humid
    - abs_humid
    - co2
    - co2_est
    - voc
    - voc_baseline
    - voc_h2_raw
    - voc_ethanol_raw
    - pm25
    - pm10_est
  value_template: 'OK'

- platform: template
  sensors:
    awair_master_bedroom_score:
      friendly_name: "Quality Score"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["score"] }}'
      unit_of_measurement: "%"
    awair_master_bedroom_temp:
      friendly_name: "Temperature"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["temp"] }}'
      device_class: temperature
      unit_of_measurement: "°C"
    awair_master_bedroom_humid:
      friendly_name: "Relative Humidity"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["humid"] }}'
      device_class: humidity
      unit_of_measurement: "%"
    awair_master_bedroom_co2:
      friendly_name: "Carbon Dioxide"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["co2"] }}'
      device_class: carbon_dioxide
      unit_of_measurement: "ppm"
    awair_master_bedroom_voc:
      friendly_name: "Total VOC"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["voc"] }}'
      device_class: volatile_organic_compounds_parts
      unit_of_measurement: "ppb"
    awair_master_bedroom_pm25:
      friendly_name: "Particulate Matter 2.5"
      value_template: '{{ states.sensor.awair_master_bedroom.attributes["pm25"] }}'
      device_class: pm25
      unit_of_measurement: "µg/m³"

Logs:

ValueError: Sensor sensor.awair_living_room_co2 has device class 'carbon_dioxide', state class 'None' unit 'ppm' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

2023-09-29 14:42:24.001 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'voc' when rendering '{{ states.sensor.awair_living_room.attributes["voc"] }}'

2023-09-29 14:42:24.001 ERROR (MainThread) [homeassistant.helpers.event] Error while dispatching event for sensor.awair_living_room to <Job track state_changed event {'sensor.awair_living_room'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({{ states.sensor.awair_living_room.attributes["voc"] }}) renders=176>: <RenderInfo Template<template=({{ states.sensor.awair_living_room.attributes["voc"] }}) renders=176> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'sensor.awair_living_room'}) rate_limit=None has_time=False exception=None is_static=False>}>>>

Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 588, in state

    numerical_value = int(value)

                      ^^^^^^^^^^

ValueError: invalid literal for int() with base 10: ''


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 591, in state

    numerical_value = float(value)

                      ^^^^^^^^^^^^

ValueError: could not convert string to float: ''


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 293, in _async_dispatch_entity_id_event

    hass.async_run_hass_job(job, event)

  File "/usr/src/homeassistant/homeassistant/core.py", line 636, in async_run_hass_job

    hassjob.target(*args)

  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1211, in _refresh

    self.hass.async_run_hass_job(self._job, event, updates)

  File "/usr/src/homeassistant/homeassistant/core.py", line 636, in async_run_hass_job

    hassjob.target(*args)

  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 429, in _handle_results

    self.async_write_ha_state()

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state

    self._async_write_ha_state()

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state

    state, attr = self._async_generate_attributes()

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 820, in _async_generate_attributes

    state = self._stringify_state(available)

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 785, in _stringify_state

    if (state := self.state) is None:

                 ^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state

    raise ValueError(

ValueError: Sensor sensor.awair_living_room_voc has device class 'volatile_organic_compounds_parts', state class 'None' unit 'ppb' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

2023-09-29 14:42:24.011 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'pm25' when rendering '{{ states.sensor.awair_living_room.attributes["pm25"] }}'

2023-09-29 14:42:24.012 ERROR (MainThread) [homeassistant.helpers.event] Error while dispatching event for sensor.awair_living_room to <Job track state_changed event {'sensor.awair_living_room'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({{ states.sensor.awair_living_room.attributes["pm25"] }}) renders=176>: <RenderInfo Template<template=({{ states.sensor.awair_living_room.attributes["pm25"] }}) renders=176> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'sensor.awair_living_room'}) rate_limit=None has_time=False exception=None is_static=False>}>>>

Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 588, in state

    numerical_value = int(value)

                      ^^^^^^^^^^

ValueError: invalid literal for int() with base 10: ''


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 591, in state

    numerical_value = float(value)

                      ^^^^^^^^^^^^

ValueError: could not convert string to float: ''


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 293, in _async_dispatch_entity_id_event

    hass.async_run_hass_job(job, event)

  File "/usr/src/homeassistant/homeassistant/core.py", line 636, in async_run_hass_job

    hassjob.target(*args)

  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1211, in _refresh

    self.hass.async_run_hass_job(self._job, event, updates)

  File "/usr/src/homeassistant/homeassistant/core.py", line 636, in async_run_hass_job

    hassjob.target(*args)

  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 429, in _handle_results

    self.async_write_ha_state()

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state

    self._async_write_ha_state()

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state

    state, attr = self._async_generate_attributes()

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 820, in _async_generate_attributes

    state = self._stringify_state(available)

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 785, in _stringify_state

    if (state := self.state) is None:

                 ^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state

    raise ValueError(

ValueError: Sensor sensor.awair_living_room_pm25 has device class 'pm25', state class 'None' unit 'µg/m³' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

API call output:

timestamp	"2023-09-29T16:26:57.175Z"
score	76
dew_point	17.87
temp	27.92
humid	54.41
abs_humid	14.7
co2	496
co2_est	865
co2_est_baseline	37682
voc	2573
voc_baseline	41562
voc_h2_raw	26
voc_ethanol_raw	38
pm25	2
pm10_est	3