node-red-contrib-myair-devices 1.0.1

Node-RED node for ResMed myAir device and sleep data using the myAir REST/GraphQL API.

npm install node-red-contrib-myair-devices

node-red-contrib-myair-devices

Support for MyAir API for ResMed CPAP/APAP devices in SmartHome projects using Node-RED.
The goal of the project is to allow using also multiple devices for the same user. The MyAir app currently only supports one device per user. For people with multiple residences or who equip a camper van with a separate device, it would be very useful to be able to consolidate the data from all their devices. A request for this feature has been rejected by ResMed support for the time being. Additionally, this project allows the data to be integrated into a smart home system, stored in a local database, and processed automatically.

Getting Started

Prerequisites: Node-RED installation. For details see here.

Install via npm

$ cd ~/.node-red
$ npm install node-red-contrib-myair-devices

Usage

In Node-RED, a node named myair-device is installed.

This node must contain a client that manages the login credentials for a MyAir account.

The device transmits its data to the cloud once a day. The node can be configured to determine how often it checks for new data. A value of 0 means no automatic checks.

On the first connection attempt, verification is required. The code received via email can be sent to the node's input via a message. The payload format must be as follows:

{ "action": "verify_mfa", "mfaCode": "<your verify code>" }

Afterward, this code will be used automatically until it is reset by the cloud, for example, due to a lack of activity.

A manual query can optionally be performed with an interval.

For example:

{ "action": "query", "beginDate": "2026-04-18", "endDate": "2026-04-19" }

Changelog

Disclaimer

The software is provided as-is under the MIT license. The author cannot be held responsible for any unintended behaviours.

Thanks

If you like our ideas and want to support further development, you can donate here:
Donate Donate
Please understand that requests from those who support us will be given priority

Exaple flow using two devices and InfluxDB

[
    {
        "id": "c1bb9c9edf257e24",
        "type": "myair-device",
        "z": "f76de702ac74f736",
        "name": "CPAP",
        "config": "de252b4e4e5a3969",
        "interval": 0,
        "x": 350,
        "y": 100,
        "wires": [
            [
                "c4e90fcd45ec084a",
                "bac5854e8c29479c"
            ]
        ]
    },
    {
        "id": "32e746d4e065f0c7",
        "type": "inject",
        "z": "f76de702ac74f736",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 100,
        "wires": [
            [
                "c1bb9c9edf257e24"
            ]
        ]
    },
    {
        "id": "b0f6a36213c31c86",
        "type": "myair-device",
        "z": "f76de702ac74f736",
        "name": "APAP",
        "config": "2192871e43d6ca37",
        "interval": 0,
        "x": 350,
        "y": 400,
        "wires": [
            [
                "9430b5f1b98c6262",
                "bac5854e8c29479c"
            ]
        ]
    },
    {
        "id": "c91042de92db5d72",
        "type": "inject",
        "z": "f76de702ac74f736",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 400,
        "wires": [
            [
                "b0f6a36213c31c86"
            ]
        ]
    },
    {
        "id": "bac5854e8c29479c",
        "type": "function",
        "z": "f76de702ac74f736",
        "name": "records",
        "func": "if (typeof msg.payload === 'string') {\n  if (!msg.payload.startsWith('MFA is required')) return\n  msg.payload = 'Please verivy'\n  return [null, msg]\n}\n\nconst patientId = msg.payload.device && msg.payload.device.fgDevicePatientId\nif (!patientId) return\nconst records = msg.payload.sleep_records\nif (!records || !records.length) return\nmsg.timestamp = records[0].time\nmsg.payload = []\nfor (const record of records) {\n  if (!record.totalUsage || !record.startDate) continue\n  const { __typename, ...cleanRecord } = record\n  msg.payload.push([{ ...cleanRecord, time: new Date(record.startDate).getTime()}, { patientId: patientId }]);\n}\nreturn [ msg, {payload: ''} ]",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 220,
        "wires": [
            [
                "134f936461a60d8d",
                "8bf8291b1e9240a7"
            ],
            [
                "31b327b8acbcd05d"
            ]
        ]
    },
    {
        "id": "8bf8291b1e9240a7",
        "type": "influxdb out",
        "z": "f76de702ac74f736",
        "influxdb": "6bf32c74b0d5edd5",
        "name": "MyAir DB",
        "measurement": "MyAir",
        "precision": "ms",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 800,
        "y": 220,
        "wires": []
    },
    {
        "id": "31b327b8acbcd05d",
        "type": "ui_text",
        "z": "f76de702ac74f736",
        "group": "2b44475370912e85",
        "order": 2,
        "width": 0,
        "height": 0,
        "name": "MyAirError",
        "label": "",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 810,
        "y": 260,
        "wires": []
    },
    {
        "id": "adf7fe18cc084bf0",
        "type": "ui_text_input",
        "z": "f76de702ac74f736",
        "name": "CpapCode",
        "label": "CPAP verification code",
        "tooltip": "",
        "group": "2b44475370912e85",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "mode": "number",
        "delay": "3000",
        "topic": "cpap",
        "sendOnBlur": true,
        "className": "",
        "topicType": "str",
        "x": 150,
        "y": 280,
        "wires": [
            [
                "3e23b86aff208703"
            ]
        ]
    },
    {
        "id": "4c8b267a417c62bc",
        "type": "ui_text_input",
        "z": "f76de702ac74f736",
        "name": "ApapCode",
        "label": "APAP verification code",
        "tooltip": "",
        "group": "2b44475370912e85",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "mode": "number",
        "delay": "3000",
        "topic": "apap",
        "sendOnBlur": true,
        "className": "",
        "topicType": "str",
        "x": 150,
        "y": 320,
        "wires": [
            [
                "3e23b86aff208703"
            ]
        ]
    },
    {
        "id": "3e23b86aff208703",
        "type": "function",
        "z": "f76de702ac74f736",
        "name": "verify",
        "func": "if (isNaN(msg.payload)) return node.error('Invalid payload: ' + JSON.stringify(msg.payload))\nconst mfaCode = msg.payload.toString()\nif (mfaCode.length !== 6) return node.error('Invalid code: ' + mfaCode)\nmsg.payload = { action: 'verify_mfa', mfaCode }\nconst empty = { payload: '' }\nswitch (msg.topic) {\n  case 'cpap': return [ msg, null, empty ]\n  case 'apap': return [ null, msg, empty ]\n}\n",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 300,
        "wires": [
            [
                "b4f262151b057825",
                "c1bb9c9edf257e24"
            ],
            [
                "b4f262151b057825",
                "b0f6a36213c31c86"
            ],
            [
                "adf7fe18cc084bf0",
                "4c8b267a417c62bc"
            ]
        ]
    },
    {
        "id": "de252b4e4e5a3969",
        "type": "myair-config",
        "name": "hausen",
        "region": "EU",
        "deviceToken": ""
    },
    {
        "id": "2192871e43d6ca37",
        "type": "myair-config",
        "name": "camper",
        "region": "EU",
        "deviceToken": ""
    },
    {
        "id": "6bf32c74b0d5edd5",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "nodered",
        "name": "InfluxDB rpi5",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    },
    {
        "id": "2b44475370912e85",
        "type": "ui_group",
        "name": "Connection",
        "tab": "b7e6cb69fb5f90db",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": true,
        "className": ""
    },
    {
        "id": "b7e6cb69fb5f90db",
        "type": "ui_tab",
        "name": "MyAir",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Node Info

Version: 1.0.1
Updated 2 weeks, 6 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

100 in the last week

Nodes

  • myair-device
  • myair-config

Keywords

  • node-red
  • resmed
  • myair
  • sleep
  • cpap

Maintainers