Add support for Qingping Air Monitor model number CGS1

Hi I just got Qingping Air Monitor the CGS1 model.
Sad to learn it has no support in HA. Could you please find a solution

Regards
Sam

Check the device in this link: https://www.amazon.com/Qingping-Monitor-Quality-Temperature-Humidity/dp/B0967WP9HS?th=1

1 Like

I have both Air Monitor and Air Monitor Lite on my network. HA currently only detect Lite model via Qingping integration. Is there a simple way how I could help to add above device to exisiting Qingping integration as device is very similar to Lite, just with touchscreen and additional tVOC sensor.

Node-Red has a plugin for the CGS1 device (node-red-contrib-air-monitor-qingping (node) - Node-RED) so it is possible to support it. The only issue is getting the access token is a little roundabout. I would really love to see the same support in HA.

I second this post. It would be great to add device support, it is such a nice device.

2 Likes

Third. :slight_smile: It’s a fantastic device. Great info and integrating into HA to control HVAC fan, an ERV smart switch etc would be awesome.

1 Like

Yes. Please support this device. It is amazing air monitor.

2 Likes

Is this support possible via BLE?

No, it is Wifi only. The Lite version is sending it’s data via BLE, but the normal version apparently isn’t, it is only using Wifi

Can it be included somehow?
I also can give access to my account if needed.
Like others, that take data from the apps themself.

Hello my dear friends!

Today I will provide you with a solution to connect your lovely Qingping Air Monitor model number CGS1 to your Home Assistant! Just successfully configured it and wanted to share with my expirience.

Lets begin.

  1. Download and register Qingping account via Qingping IoT app or Qingping+ app. Easy, huh?

  2. Add your device to this application (see device instruction). But I think you guys already did that.

  3. Go to https://developer.qingping.co/ and login there with your Qingping account (the same account which you used at Step 1).

  4. At the top menu under your account name find menu “Access management” and find your App key and App secret. This credentials will need you to access to Qingping Open API. Copy them.

  5. Go to https://www.base64encode.org/ and paste App key:App secret, e.g. string must look like xxxx-xxx:yyyyyyyyyyyyyyyyyyyy, then encode and copy encoded result (do not forget divide values with colon).

  6. Now time to configure your Home Assistant. Open your secrets.yaml at Home Assistant’s folder. You will store there your credentials from Step 5. Add a line:

qingping_auth: "Basic RESULT"

where RESULT = base64 encoded App key and App secret from Step 5.

e.g.

qingping_auth: "Basic eHh4eC14eHg6eXl5eXl5eXl5eXl5eXl5eXl5eXk="
  1. Open your automations.yaml at Home Assistant folder. Add automation to retrieve Token to access Qingping Open API:
- id: 'QingpingUpdateToken'
  alias: Update Token Bearer
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.api_access_token_bearer
  condition: []
  action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.api_token_bearer
      value: '{{ trigger.to_state.state }}'
  mode: single

Save file.

  1. Open configuration.yaml at Home Assistant’s folder. Now we will add our sensors. First sensor is for API Access Token and second sensor recieves our information. I think you want to make “API Access Token Bearer” sensor not visible on your Dashboard. At QingPing sensors you can change unique_id on whatever you want, but keep in mind, this params needed if you want to modify sensors data from Home Assistant’s UI. The values must be unique for each sensor.
rest:
  - resource: "https://oauth.cleargrass.com/oauth2/token"
    scan_interval: 7000
    timeout: 60
    method: "POST"
    headers:
      Authorization: !secret qingping_auth
      Content-Type: "application/x-www-form-urlencoded"
    payload: 'grant_type=client_credentials&scope=device_full_access'
    sensor:
      - name: "API Access Token Bearer"
        unique_id: "api_access_token_bearer"
        value_template: "Bearer {{ value_json['access_token'] }}"
  - resource: "https://apis.cleargrass.com/v1/apis/devices"
    scan_interval: 60
    timeout: 60
    method: "GET"
    headers:
      Authorization: "{{ states('input_text.api_token_bearer') }}"
      Content-Type: "application/json"
    sensor:
      - name: "QingPing Battery"
        unique_id: "582D366666B9"
        value_template: "{{ value_json.devices.0.data.battery.value }}"
      - name: "Temperature"
        unique_id: "582D366666B9T"
        value_template: "{{ value_json.devices.0.data.temperature.value | round(2) }}"
      - name: "Humidity"
        unique_id: "582D366666B9H"
        value_template: "{{ value_json.devices.0.data.humidity.value | round(2) }}"
      - name: "tVoc"
        unique_id: "582D366666B9Tvoc"
        value_template: "{{ value_json.devices.0.data.tvoc.value | round(1) }}"
      - name: "co2"
        unique_id: "582D366666B9C"
        value_template: "{{ value_json.devices.0.data.co2.value }}"
      - name: "pm25"
        unique_id: "582D366666B9pm25"
        value_template: "{{ value_json.devices.0.data.pm25.value }}"
      - name: "pm10"
        unique_id: "582D366666B9pm10"
        value_template: "{{ value_json.devices.0.data.pm10.value }}"

Save file. Of course, if you have more than 1 device registered at Qingping, you can easily play with device index (0 and more) and filter result by MAC of your device v1/apis/devices?mac=XXXXXX.

  1. Go to control panel. Go to Settings → Devices & Services → Helpers. Create Helper with Text type, make name of it “api_token_bearer”. This field will store our oAuth token for Qingping Open API. Make it non-visible.

  2. Restart your Home Assistant. Enjoy! If you have any troubles, then check home-assistant.log. If you want to debug requests and responses from Qingping Open API, do not forget to add logger configuration to your configuration.yaml:

logger:
  default: info
  logs:
    homeassistant.components.rest: debug

P.S. If you getting problems with auth data after system restart or whatever, try to reduce token update interval from 7000 secs to 900 secs (for example or less at API Access Token Bearer sensor). By default, Qingping returns 7199 secs TTL for token.

scan_interval: 900

Good luck!

3 Likes

Works perfectly, thank you!

Here is a suggested modification to the configuration.yaml to give all the devices their correct device classes - essential otherwise some of the devices do not show up in Apple Home.

sensor:
      - name: "QingPing Battery"
        unique_id: "582D366666B9"
        device_class: "battery"
        value_template: "{{ value_json.devices.0.data.battery.value }}"
      - name: "Temperature"
        unique_id: "582D366666B9T"
        device_class: "temperature"
        unit_of_measurement: "degrees"
        value_template: "{{ value_json.devices.0.data.temperature.value | round(2) }}"
      - name: "Humidity"
        unique_id: "582D366666B9H"
        device_class: "humidity"
        value_template: "{{ value_json.devices.0.data.humidity.value | round(2) }}"
      - name: "tVoc"
        unique_id: "582D366666B9Tvoc"
        device_class: "volatile_organic_compounds"
        value_template: "{{ value_json.devices.0.data.tvoc.value | round(1) }}"
      - name: "co2"
        unique_id: "582D366666B9C"
        device_class: "carbon_dioxide"
        value_template: "{{ value_json.devices.0.data.co2.value }}"
      - name: "pm25"
        unique_id: "582D366666B9pm25"
        device_class: "pm25"
        value_template: "{{ value_json.devices.0.data.pm25.value }}"
      - name: "pm10"
        unique_id: "582D366666B9pm10"
        device_class: "pm10"
        value_template: "{{ value_json.devices.0.data.pm10.value }}"
2 Likes

I’m surprised to see nobody mentions (or figured out) the (local!) MQTT functionality. I’m using this for over 2 years now, without the need of having the device phone home or to rely on public API’s.

Qingping (formerly known as Cleargrass) is a great and friendly to communicate with company. However, as a Chinese company, you know the drill when the Communist Party is in charge. After setting up and updating the MQTT device settings online, I cut-off internet access. It is called the privatization functionality.

You can easily ask Qingping support to enable, where they will ask you for your MQTT server details, which can be your local server. They will send the settings to your device. After resetting the device, it will start communicating with your MQTT server, which you can use to hook on HA.

With recent firmware, you could do the whole setup by your own, but it requires a bit more work via https://developer.qingping.co/.

Also check https://developer.qingping.co/main/private/device_private

2 Likes

MQTT seems like a great solution! Would you mind giving a little detail about how you configured it? I see the instructions in the link you sent but does Home Assistant just pick it up? Can you just pick whatever topic names you want?

Hi,

There is a Russian website that explains the Mqtt setup very good, just use Google translate.

3 Likes

Amazing! Thank you! Wow that google translation is super clear too.

1 Like

You actually do not have to Email, since Mqtt has been enabled automatic for everyone.

Thanks a lot for your help, I have set my MQTT broker and I have configured the Private Access on the developer platform of Qingping but now I’m stuck.

I can’t understand, from the russian page, the last step with all the code, where do I have to put it, and if it’s correct, because there’s a lot of cirillic characters… can you please help? Thanks!!

The last part you fill in your Configuration.yaml

mqtt:
Sensor:
- object_id: AIR_co2
name: “Air CO2”
state_topic: “qingping/macaddress/up”
device_class: carbon_dioxide
unique_id: “qingping_dioxide”
value_template: >-
{{ value_json.sensorData.0.co2.value
if value_json.type==“12” }}
unit_of_measurement: “ppm”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”
- object_id: AIR_temp
name: “Air Temperature”
state_topic: “qingping/macaddress/up”
device_class: temperature
unique_id: “qingping_temp”
value_template: >-
{{ value_json.sensorData.0.temperature.value|round(2)
if value_json.type==“12” and value_json.sensorData.0.temperature.status==0 }}
unit_of_measurement: “°C”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”
- object_id: AIR_hum
name: “Air Humidity”
state_topic: “qingping/macaddress/up”
device_class: humidity
unique_id: “qingping_hum”
value_template: >-
{{ value_json.sensorData.0.humidity.value|round(2)
if value_json.type==“12” and value_json.sensorData.0.humidity.status==0 }}
unit_of_measurement: “%”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”
- object_id: AIR_tvoc
name: “Air Tvoc”
state_topic: “qingping/macaddress/up”
device_class: volatile_organic_compounds
unique_id: “qingping_tvoc”
value_template: >-
{{ (value_json.sensorData.0.tvoc.value/218.77)|round(3)
if value_json.type==“12” and value_json.sensorData.0.tvoc.status==0 }}
unit_of_measurement: “µg/m³”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”
- object_id: AIR_pm10
name: “Air pm10”
state_topic: “qingping/macaddress/up”
device_class: pm10
unique_id: “qingping_pm10”
value_template: >-
{{ value_json.sensorData.0.pm10.value
if value_json.type==“12” }}
unit_of_measurement: “µg/m³”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”
- object_id: AIR_pm25
name: “Air pm25”
state_topic: “qingping/macaddress/up”
device_class: pm25
unique_id: “qingping_pm25”
value_template: >-
{{ value_json.sensorData.0.pm25.value
if value_json.type==“12” and value_json.sensorData.0.pm25.status==0 }}
unit_of_measurement: “µg/m³”
device:
identifiers: [“macaddress”]
name: “Air monitor”
model: “CGS1”
manufacturer: “qingping”

The part where it says “macaddress” you need to fill in the Mac address of your Qingping Air Monitor

Then restart your HA and then you’ll find the sensors under the Mqtt integration

hey. I tried the solution posted by Vladimir Lisin, but it doesnt seem to work for me. In the log file it says:

2023-09-10 11:59:21.160 DEBUG (MainThread) [homeassistant.components.rest] Finished fetching rest data data in 1.198 seconds (success: True)
2023-09-10 11:59:21.160 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.160 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.160 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.161 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.161 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.161 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 11:59:21.161 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"code":0,"msg":"header: Authorization format incorrect","traceId":"33a59698ffa25283:33a59698ffa25283:0000000000000000:0","timestamp":1694365161}
2023-09-10 12:00:20.963 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://apis.cleargrass.com/v1/apis/devices

can someone provide any tips on this?