Formatting Returned Sensor Data

I am trying to format that data that is returned from my Smoke/Co2/VOC detector. As you can see below, several attributes are being returned from the entity state.

My goal is to have the VOC and Humidity sensors print something more readable (separating the ‘value’, ‘status’ and ‘unit’). Could someone kindly point me in the right direction on how to do this?

I have yet to start my journey in templating, but I have a feeling this is the direction I need to take.

Any advice is appreciated. Thanks!

Yes, it is.

And how you do that depends on what integration you’re currently using.

1 Like

You could use template sensors to parse these strings into the value of the sensor and the availability. You would have to hard code the unit though, as template sensors don’t support templating the unit of measurement.

However, I’m curious what integration you’re using to get these sensors. That integration shouldn’t be providing values that look like this and should be doing the work for you.

For completeness sake, here’s an example template to parse the value out of these strings.

{% set regex_results = states('sensor.upstairs_detector_humidity') | regex_findall(":[^,}\d\w]*([^,} ']*)[^,}]*[,}]") %}
{{ regex_results[0] }}
1 Like

Thanks for the reply.

I am using an unofficial Kidde Smoke Detector integration for HA.

The integration is based on a Python Wrapper but only pulls data for Smoke and Co2 from the API

My device also has Air Quality Sensors that I would like to use in HA.

To get the data seen in my initial screenshot, I had to add sensors into the integration using FileEditor (see below). Added sensors are “humidity”, “temperature”, “tvoc”.

SensorEntityDescription(“smoke_level”, icon=“mdi:smoke”, name=“Smoke Level”),
SensorEntityDescription(“co_level”, icon=“mdi:molecule-co”, name=“CO Level”),
SensorEntityDescription(“humidity”, icon=“mdi:molecule-co”, name=“Humidity”),
SensorEntityDescription(“temperature”, icon=“mdi:molecule-co”, name=“Temperature”),
SensorEntityDescription(“tvoc”, icon=“mdi:molecule-co”, name=“VOCs”),
“battery_state”, icon=“mdi:battery-alert”, name=“Battery State”
SensorEntityDescription(“last_seen”, icon=“mdi:home-clock”, name=“Last Seen”),
“last_test_time”, icon=“mdi:home-clock”, name=“Last Test Time”

note: formatting not correct

I was able to determine the other values based on this screenshot:

I will start taking a look at templating regex (I remember seeing this some of my searches but wasn’t sure if that was the right path.

Appreciate your help!

You might just want to wait then. It looks like this integration is brand new and the developer put a placeholder issue to fix the sensor data types just a few days ago.

You could create an issue in the github repository to request your new sensors to be added, or even better, create a PR for them (if that’s within your github comfort level).

It’s the last line of the file that you quoted where it’s returning the whole block of json as the value of the sensor. If you want to keep fiddling with the python, you should be able to get it to return just the 'value' part.

Thank you atlflyer for taking the time to look into this and checking into the details of the integration itself.

I just used Jupyter Notebook to pull some device specific info (including my specific sensors). I will pass this along to the developer of this integration to aid with the creation of new sensors.

Have a great day/night! Appreciate the support.