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
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.
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.
platforms under sensor require a list. So you need list indicator.
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.
Value template requires quotes when it’s a single line
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:
Order of operation matters, because of this filters don’t always need parenthesis.
1/37 is eqivalent to dividing by 37. No reason to make the parser work harder to get to your answer.
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.
I also have some 2nd Gen Airthings sensors but connected through their modern cloud API… it’s great by the way… I highly recommend their View Plus hardware.
Anyway, wanted to update the template syntax to help out the other Home Assistant Newbs out there since the above syntax seems to be outdated and doesn’t work as of 2022.
Also for the newbs, this text gets saved into your configuration.yaml file. After a system restart, you should have a new sensor show up.
You can also test these template outputs in real-time without restarting by using the ‘Template Editor’ in the ‘Developer Tools’ sidebar, then copy the test to your configuration.yaml file after you’ve confirmed it works in the Template Editor.
Thank you qwertyphile!!! This was awesome and worked like a charm. The last note about where to put this entry has solved a long standing issue for me. I haven’t been able to figure out template entries.
did you ever figure this out? I’ve tried adding it to the configuration.yaml as well as creating a jinja file in the custom_templates folder, but neither seem to work.
should work fine, it may cause issues if sensor.basement_radon_radon goes unavailable. If that’s causing your problems, you should change float to float(0)