Converting sensor reading from one unit to another

I have an AirThings air quality sensor in my basement. I was able to pull in the data to HA with their API but the radon value is being reported in Bq/m^3 versus pCi/L. I would rather it be shown in pCi/L.

1 pCi/L = 37 Bq/m^3

How would I go about changing this in my dashboard? The entity is simply being reported in as:

entity: sensor.airthings_basement_radon

I just want to divide whatever the entity is being reported as by 37. I’d also like to be able to change the unit being shown, if that’s possible.

I’m really new to HA and all this. Any help would be appreciated!

1 Like

Take a look at template sensors. Somewhere down below is an example on how to create a template sensor to do a type conversion:

Look for “changing the unit of measurement of another sensor”.

That’s perfect. Thanks!!

here’s how I just did it…

template:

  • sensor:
    • name: “Airthings Base - Current Radon (US)”
      unit_of_measurement: “pCi/L”
      state_class: measurement
      state: “{{ (states(‘sensor.7138npc_radon’) | float / 37) | round(2) }}”

Strange. I get this error: ValueError: could not convert string to float: ‘“1.08”’

template:
  - sensor:
      name: “Airthings Radon (4)”
      unit_of_measurement: “pCi/L”
      state_class: measurement
      state: “{{ (states('sensor.airthings_radon')|float / 37) | round(2) }}”

maybe try a different entity ?

I get the following error using the suggested template sensor:

Log details (ERROR)
Logger: homeassistant.core
Source: core.py:1571
First occurred: 4:32:01 PM (1 occurrences)
Last logged: 4:32:01 PM

Error running job: <Job onetime listen homeassistant_start <function _async_at_core_state.<locals>._matched_event at 0x7f6c5dfa60> HassJobType.Callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f6c5dfa60>>>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 663, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: '“1.78”'

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1571, in async_fire_internal
    self._hass.async_run_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 947, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1429, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 947, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 44, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 947, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 487, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1065, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1251, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 947, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 435, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1009, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1067, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1015, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 665, in state
    raise ValueError(
ValueError: Sensor sensor.airthings_radon_4 has device class 'None', state class 'measurement' unit '“pCi/L”' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '“1.78”' (<class 'str'>)

Been fighting with this issue tonight with a new airthings device. Looks like the Airthings dashboard is only rounding to 1 decimal point, but I’m graphing both 2 and 1 decimal points to compare over time. Here’s what I did in the configuration.yaml file:

sensor:
  - platform: template
    sensors:
      airthings_radon_pci_l:
        friendly_name: "Guest Room Radon"
        unit_of_measurement: "pCi/L"
        value_template: >
          {% set radon_value = states('sensor.view_plus_radon') | float %}
          {% if radon_value > 0 %}
            {{ (radon_value / 37) | round(2) }}
          {% else %}
            0
          {% endif %}

      airthings_radon_pci_l_round_1:
        friendly_name: "Guest Room Radon Rounded 1"
        unit_of_measurement: "pCi/L"
        value_template: >
          {% set radon_value = states('sensor.view_plus_radon') | float %}
          {% if radon_value > 0 %}
            {{ (radon_value / 37) | round(1) }}
          {% else %}
            0
          {% endif %}