Qingping Air monitor lite homeyscript

Hi all,

I made a quick integration to get data from Qingping+ for the Qingping Air Monitor Lite device. Be sure to use the Qingping+ app on your phone and use an account. The device must be set in qingping mode instead of homekit mode.
Be sure to adjust the Authorization token as described here: https://developer.qingping.co/main/oauthApi.

const params = new URLSearchParams();

params.append('grant_type', 'client_credentials');

params.append('scope', 'device_full_access');

var result = await fetch("https://oauth.cleargrass.com/oauth2/token", {

  method: 'post',

  headers: {

    'Authorization': 'Basic CHANGE_THIS_KEY',


  body: params,


if (!result.ok)   throw new Error(result.statusText);

const body = await result.json();


var access_token= body.access_token;

await tag("qingping_access_token", access_token);

// get device data

var result = await fetch("https://apis.cleargrass.com/v1/apis/devices?timestamp=" + Date.now().toString(), {

  method: 'get',

  headers: {

    'Authorization': 'Bearer ' + access_token,



if (!result.ok)   throw new Error(result.statusText);

const body2 = await result.json();

var data = body2.devices[0].data


var {timestamp,temperature,humidity,  co2,pm25} = data;

console.log(timestamp,temperature,humidity,  co2,pm25);

await tag("qingping_timestamp", timestamp.value);

await tag("qingping_temperature", temperature.value);

await tag("qingping_humidity", humidity.value);

await tag("qingping_co2", co2.value);

await tag("qingping_pm25", pm25.value);

Hello Thomas,

Thanks for the integration.
Could you help me how to get the Authorization token? I cant really figure it out.

And do i use this code with HomeyScript?

Yes! Do you have a app key and app secret from https://developer.qingping.co/personal/permissionApply?

I have a key and secret, do I need to do anything else?

And can you share some inspirational flows?

I retrieved this from developer page
App secret: yyyyyyy

I edited the script accordingly:

'Authorization': 'xxxxxxxxxx', or
'Authorization': 'yyyyyyyyyy',

This is the output of the script

:x: Script Error
:warning: Error: Bad Request
at Qingping.js:21:25
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async HomeyScriptApp.runScript (/app.js:312:22)
at async Object.runScript (/api.js:24:18)

Hi @tjaadvd , thanks for your script. I used it for my Homey except I inserted my app key from Qingping, where you typed ‘change_this_key’. I get the same script error output as Wout in the last message. Not sure where my app secret key goes.

Can you help? I’m afraid I’m new to scripts so am quite confused by how they work! Appreciate your time.

Hi guys,

The trick to generate the Authorization key is to combine the client_id (App Key) and client_secret (App Secret) and ‘encode’ them with base64. Base64 is an encoding originally build for email attachments.

  • Go to https://www.base64encode.org/
  • paste the App Key, then the ‘:’ character, and then the App Secret. For example “_GoSI9xxx:c2ba57537b5311eb9e7fxxxxxxxxxxxx”.
  • Click on the convert button
  • Copy the resulting encoded string (for example “X0dvU0k5eU…”)
  • Then replace CHANGE_THIS_KEY with the string that you copied. The line now looks like this: ‘Authorization’: ‘Basic X0dvU0k5eU…’,

That should do the trick! This script uses the first qingping device in your account. If you have multiple you can create a new script and change devices[0] to devices[1].

If you’ve created the homeyscript (through https://my.homey.app) and it works, you can use it with a flow like this: Gedeelde Flow | Homey. That flow runs every 10 minutes, and uses the homeyscript in the ‘And’ (conditions) section. The first actions that set Logic aren’t important. I’ve created a virtual device in Homey of type ‘sensor’ and this script sets the values for that virtual device. In order to create a virtual device in Homey you have to go to Settings in the app → Experiments → Virtual devices.

Great! thank you, I can now pull air quality data via homeyscript. unfortunately it seems that the Homey app now no longer includes virtual sensors, only some other virtual types e.g. switch. the functionality might be suspended for now.

You can use the Virtual Devices app for sensors.

1 Like

That works. Thanks!

1 Like


Hi, great you have figured this out!
I could not use my Qingping on Homey 2023 any more.

I have one question, my script is running fine, i got the richt values.

timestamp: { value: 1679155200 },
temperature: { value: 21.49 },
humidity: { value: 52.39 },
co2: { value: 789 },
pm25: { value: 1 },
pm10: { value: 2 }
{ value: 1679155200 } { value: 21.49 } { value: 52.39 } { value: 789 } { value: 1 }

:white_check_mark: Script Success
:leftwards_arrow_with_hook: Returned: undefined

But when using it in a flow i got an error back, see screenshot.

Maybe you can help me with this?


I Have the same problem. Don’t know what the problem is

It looks like the script give an error. I can’t test a new script, but i asked ChatGPT to rewrite the old script. Maybe, just maybe it works;

const { OAuth2 } = Homeyapi('oauth2');
const { Http } = Homeyapi('http');

const oauth2 = new OAuth2({
  client_id: 'CHANGE_THIS_KEY',
  client_secret: '',
  scopes: ['device_full_access'],
  authorization_uri: 'https://oauth.cleargrass.com/oauth2/auth',
  token_uri: 'https://oauth.cleargrass.com/oauth2/token'

const http = new Http();

(async () => {
  try {
    const { access_token } = await oauth2.getToken();

    // Store the access token as a tag
    await Homey.flowToken.set('qingping_access_token', access_token);

    // Get device data
    const { devices } = await http.get('https://apis.cleargrass.com/v1/apis/devices', {
      headers: {
        'Authorization': `Bearer ${access_token}`

    // Extract the data from the first device
    const { data } = devices[0];

    // Store the data values as tags
    await tag('qingping_timestamp', data.timestamp.value);
    await tag('qingping_temperature', data.temperature.value);
    await tag('qingping_humidity', data.humidity.value);
    await tag('qingping_co2', data.co2.value);
    await tag('qingping_pm25', data.pm25.value);

    // Log the data values
    console.log(data.timestamp.value, data.temperature.value, data.humidity.value, data.co2.value, data.pm25.value);
  } catch (error) {

This is the result of the script:

:x: Script Error
:warning: ReferenceError: Homeyapi is not defined
at Qingping3.js:1:20
at processTicksAndRejections (node:internal/process/task_queues:96:5)

Ok, was worth a try😰