Converting Sensor Measurement Units

I have a Airthings Wave Radon Detector, which is reporting Radon values in units Bq/M^3 via MQTT to HA. Unfortunately, in the US, Radon levels are read in units of PCi/L. Converting from Bq/M^3 to PCi/L is quite easy, just divide by 37. How can I add this conversion in HA so that PCi/L is displayed?

I’ve tried the following via templating, but continue to encounter errors:

sensor.radon_24hrsUS would be the new entity that I am trying to create

sensor.radon_24hrs is the current entity that is reporting units in Bq/M^3

sensor:
  platform: template
  sensors:
    sensor.radon_24hrsUS:
    unit_of_measurement: 'pCi/L'
    value_template: {{ (float(states('sensor.radon_24hrs')) * 1 / 37) }}

Always those dreadful value_templates :slight_smile:

Try the following:
value_template: “{{(states.sensor.radon.state | float * 1/37)}}”

You don’t say what the errors are, but you might have a couple problems unrelated to the value template (it looks fine to me): 1) the yaml formatting has incorrect indentation, 2) entity names can only be lowercase but you have uppercase.

Try this:

sensor:
  - platform: template
    sensors:
      sensor.radon_24hrs_us:
        unit_of_measurement: 'pCi/L'
        value_template: {{ float(states('sensor.radon_24hrs')) / 37 }}

As for the value template, these all seem to be the same, so take your pick. In templates I find the filter versions easier to read since it separates the logic to get the sensor state and the conversion.

{{ float(states('sensor.radon_24hrs')) / 37) }}
{{ float(states('sensor.radon_24hrs')) * 1 / 37 }}
{{ states('sensor.radon_24hrs') | float / 37) }}
{{ states('sensor.radon_24hrs') | float * 1 / 37) }}

Thanks for the help fversteegen & freshcoast!

BTW - Completely forgot about the capital letters!

I tried the entry below:

sensor:
  platform: template
  sensors:
    sensor.radon_24hrs_us:
      unit_of_measurement: 'pCi/L'
      value_template: {{(states.sensor.radon_24hrs.state | float * 1/37)}}

But receive the error;

Error loading /home/homeassistant/.homeassistant/configuration.yaml: invalid key: “OrderedDict([(’(states.sensor.radon_24hrs.state | float * 1/37)’, None)])”
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 323, column 0

You had a number of things wrong.

  1. platforms under sensor require a list. So you need list indicator.
  2. You made the sensor entity_id invalid by adding a period in it. Not sure why you named it sensor.radon_24hrs_us. Just name it radon_24hrs_us and it will be created as sensor.radon_24hrs_us.
  3. Value template requires quotes when it’s a single line
  4. You should be using the states method so that it properly gives you a result at all times (even during startup).

Just a few pointers:

  1. Order of operation matters, because of this filters don’t always need parenthesis.
  2. 1/37 is eqivalent to dividing by 37. No reason to make the parser work harder to get to your answer.
sensor:
  - platform: template
    sensors:
      radon_24hrs_us:
        unit_of_measurement: 'pCi/L'
        value_template: "{{ states('sensor.radon_24hrs') | float / 37 }}" 
1 Like

Whoops, copy and paste errors on my part. Thanks for the correction @petro. :+1:

Ah yeah, I didn’t even notice your post. I think you just had an extra ), no biggie. EDIT: Did i reply to you with that post? Meant to reply to @curt7000

Thanks for the tips @petro, its now working! I added some rounding, the confirmed working config is below. I broke up my sensors to individual components a long way back as listing them was causing a bunch of errors. I need to merge them.

sensor 15:
  platform: template
  sensors:
    radon_24hrs_us:
      unit_of_measurement: 'pCi/L'
      value_template: "{{ (states('sensor.radon_24hrs') | float / 37) | round(2) }}"

sensor 16:
  platform: template
  sensors:
    radon_lifetime_us:
      unit_of_measurement: 'pCi/L'
      value_template: "{{ (states('sensor.radon_lifetime') | float / 37) | round(2) }}"

Yes … Radon mitigation is in my future.

1 Like