Xiaomi ClearGrass Air Detector

nevermind, edited out a stupid question…

First of all i’m not a developer. But how come that the official release have less functions, only two of five sensors working and the custom_component has all five? It makes no sense.
Here’s the code for getting the attributes as ordinary sensors if someone needs it.

cleargrass_tvoc:
        friendly_name: 'ClearGrass tVOC'
        unit_of_measurement: 'mg_m3'
        value_template: "{{ state_attr('sensor.cleargrass_airmonitor', 'tvoc') }}"
      cleargrass_co2:
        friendly_name: 'ClearGrass co2'
        unit_of_measurement: 'ppm'
        value_template: "{{ state_attr('sensor.cleargrass_airmonitor', 'co2') }}"
      cleargrass_temp:
        friendly_name: 'ClearGrass Temp'
        unit_of_measurement: 'C'
        value_template: "{{ state_attr('sensor.cleargrass_airmonitor', 'temperature') }}"
      cleargrass_humidity:
        friendly_name: 'ClearGrass Fukt'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('sensor.cleargrass_airmonitor', 'humidity') }}" 
1 Like

Hi, could you please explain further in what config have you added this corrections? I have working ClearGrass based on https://github.com/Cheaterdev/clear_grass-ha but it only shows AQ Pm 2.5 as sensor

1 Like

You can see in the entitys attributes all the diifferent sensors. But i don’t need the custom component anymore i now got all the values from the native component.

air_quality:
  - platform: xiaomi_miio
    name: Xiaomi Airmonitor
    host: 192.168.0.11
    token: xxxx
1 Like

image

Yeah, i have the same showing, but badge can show only pm 2.5. I wish i could see as badge co2 and others. Or i am missing something obvious?

Do you see the attributes at all?

Yes, same as you have

carbon_dioxide: 615
particulate_matter_2_5: 7.1
total_volatile_organic_compounds: 266
temperature: 20.4
humidity: 39.9
unit_of_measurement: µg/m³
friendly_name: Xiaomi Airmonitor
icon: ‘mdi:cloud’

Weel, the you can use my valute_template example above in order to get the entities.

I read about https://www.home-assistant.io/docs/configuration/templating/ and after changing your code and testing if finally works, thank for help!

# Sensors
sensor:
  - platform: template
    sensors:  
        ccleargrass_tvoc:
                friendly_name: 'ClearGrass tVOC'
                unit_of_measurement: 'mg_m3'
                value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'total_volatile_organic_compounds') }}"
        ccleargrass_co2:
                friendly_name: 'ClearGrass co2'
                unit_of_measurement: 'ppm'
                value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'carbon_dioxide') }}"
        ccleargrass_temp:
                friendly_name: 'ClearGrass Temp'
                unit_of_measurement: 'C'
                value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'temperature') }}"
        ccleargrass_humidity:
                friendly_name: 'ClearGrass Humidity'
                unit_of_measurement: '%'
                value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'humidity') }}" 
3 Likes

Thx @Magren and @Broval, my final config (added PM2.5 as sensor, added icons, updated units):

# Xiaomi Air Quality Monitor
#   co2, humidity, pm25, temperature, tvoc
air_quality:
  - platform: xiaomi_miio
    name: Xiaomi Airmonitor
    host: CLEARGRASS_IP
    token: CLEARGRASS_TOKEN
# Sensors
sensor:
  - platform: template
    sensors:
      ccleargrass_co2:
        friendly_name: 'ClearGrass CO2'
        icon_template: 'hass:molecule-co2'
        unit_of_measurement: 'ppm'
        value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'carbon_dioxide') }}"
      ccleargrass_humidity:
        friendly_name: 'ClearGrass Humidity'
        icon_template: 'hass:water-percent'
        unit_of_measurement: '%'
        value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'humidity') }}"
      ccleargrass_pm25:
        friendly_name: 'ClearGrass PM2.5'
        icon_template: 'hass:grain'
        unit_of_measurement: 'µg/m³'
        value_template: "{{ states('air_quality.xiaomi_airmonitor') }}"
      ccleargrass_temp:
        friendly_name: 'ClearGrass Temp'
        icon_template: 'hass:thermometer'
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'temperature') }}"
      ccleargrass_tvoc:
        friendly_name: 'ClearGrass tVOC'
        icon_template: 'hass:grain'
        unit_of_measurement: 'mg/m3'
        value_template: "{{ state_attr('air_quality.xiaomi_airmonitor', 'total_volatile_organic_compounds') }}"   

Hi!

Does anyone know if there’s a client lib, docs or something to get data instead of locally, from quingping/xiaomi/whatever servers?

I prefer local integrations at home, sure, but we are setting some of this in different locations and hasn’t been able to get data remotely :frowning:

Great work @bodgan !

Thanks!

Hello all!

If someone interested displaying tVOC units in mg/m³ instead of ppb, I found the right formula:

      air_monitor_tvoc:
        friendly_name: "Air Monitor tVOC"
        value_template: "{{ ((state_attr('air_quality.air_monitor', 'total_volatile_organic_compounds') | float)* 12.187 * 110 / (273.15 + (state_attr('air_quality.air_monitor', 'temperature') | float)) / 1000) | round(3)}}"
        icon_template: mdi:molecule
        unit_of_measurement: "mg/m³"

I hope this help to someone.

1 Like

Using the Bogdan’s plugin:
image

Using Xiaomi Miio integration:
image

Now feel the difference…
No battery info with Xiaomi Miio integration.
Bogdan, thank you very much!

P.S. Has anyone understood a use for a new device_class=carbon_dioxide?
Tried to use it for a template sensor for co2, did not find any advantages, then removed this device_class from the sensor.

Thanks for the integration! Everything works like a charm

My sensors show AQI but it’s actually PM2.5 value, right?

OK, there’s an interesting issue
I created sensors for the attributes like this

      cleargrass_1_temp:
        friendly_name: 'ClearGrass 1 Temperature'
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('sensor.ClearGrass1', 'temperature') }}"
        icon_template: mdi:thermometer

But whatever I use as a unit of measurement here, the lovelace graph shows exactly ‘C’. So I can not have other temp readings on the same graph with this temperature.
What can be the problem? Thanks

P.S.: I forgot to mention that the object card shows correct units like
ClearGrass 1 Temperature 25,5 °C

Have you cleared the browser’s cache?

Try with ANOTHER unit:
My card:


The sensor:

      cleargrass_1_temp:
        friendly_name: 'Xiaomi CG Temp'
        unit_of_measurement: "\u00b0C"
        device_class: temperature
        value_template: "{%  set SOURCE_DEVICE = 'xiaomi_cg_1' -%}
                         {%- set SOURCE_ATTR = 'temperature' -%}
                         {%- set SOURCE_SENSOR_FULL = 'sensor.' + SOURCE_DEVICE -%}
                         {%- set DEST_DEVICE = 'cleargrass_1' -%}
                         {%- set DEST_SENSOR = 'temp' -%}
                         {%- set DEST_SENSOR_FULL = 'sensor.' + DEST_DEVICE + '_' + DEST_SENSOR -%}
                         {%- if states(SOURCE_SENSOR_FULL) in ['unavailable','unknown'] -%}
                         {{ states(DEST_SENSOR_FULL) }}
                         {%- else -%}
                         {{ state_attr(SOURCE_SENSOR_FULL,SOURCE_ATTR) }}
                         {%- endif %}"
1 Like

Thanks Ildar!
I actually have 3 CGS1.
I only replaced unit_of_measurement: ‘°C’ to “\u00b0C” in one sensor definition and restarted the server - all 3 graphs started to show correct units!
More interesting, I set the value back to ‘°C’ but the graph remained correct!
That’s not the cache, because I even changed the domain but the values remained wrong. Also the graphs seem to get generated each time.
I am a fresh user of HA but I see that it definitely has its quirks.
The problem solved anyways.
Thanks a lot!

Anyway, I think it was cached probably.
Last year (September 2020, I just started learning HA) I had a similar case: in “config.yaml” it was specified "°C" but history-graph displayed “C”.

1 Like