node-red-contrib-netatmo-cloud 1.0.0

Node-RED nodes for the Netatmo cloud API (weather station and any endpoint) with built-in OAuth2 refresh-token rotation and persistent token storage. No extra flow needed.

npm install node-red-contrib-netatmo-cloud

node-red-contrib-netatmo-cloud

Node-RED nodes for the Netatmo cloud API, with OAuth2 token handling built in. No extra authentication flow, no global context, no token file nodes: drop in one node, set three environment variables, done.

  • weather station node: reads getstationsdata (indoor station, outdoor, wind, rain and extra indoor modules). Output either the unchanged API response or one message per module.
  • netatmo api node: calls any other endpoint (getmeasure, gethomecoachsdata, homesdata, homestatus, ...) with the same account.
  • Netatmo account config node: handles the rotating refresh token and stores it safely on disk.

Requires Node.js 18 or newer and Node-RED 3 or newer (tested with Node-RED 4.1 and 5.0).

Why another Netatmo node?

Since Netatmo switched to OAuth2 with rotating refresh tokens, the existing Node-RED Netatmo packages (last published 2017 to 2022) no longer keep a working login: every refresh issues a new refresh token and invalidates the old one. If that new token is not stored, the login is lost after the next restart.

This package keeps the token chain alive:

  • the access token is refreshed on demand (5 minutes before it expires, or when Netatmo rejects it), parallel requests share a single refresh;
  • the new token pair is written to a token file atomically (temp file, fsync, rename), so a restart, a container update or a power cut in the middle of a write does not lose the token;
  • if the stored token is rejected, the initial refresh token from the configuration is tried as fallback; a newly configured initial token is preferred over an old stored chain, so re-authorising only means setting a new token;
  • after a rejected token the node pauses 15 minutes instead of hammering the Netatmo API; network errors never count as authorisation errors.

Install

In the Node-RED editor: Menu → Manage palette → Install, search for node-red-contrib-netatmo-cloud.

Or on the command line in your Node-RED user directory (usually ~/.node-red):

npm install node-red-contrib-netatmo-cloud

Setup

  1. Create an app on dev.netatmo.com/apps. Note the client ID and client secret.

  2. In the app, use the token generator: choose the scopes you need (read_station for weather stations, read_homecoach, read_thermostat, ... for other products) and generate a token. Copy the refresh token.

  3. Provide the three values as environment variables of Node-RED:

    Variable Value
    NETATMO_CLIENT_ID client ID
    NETATMO_CLIENT_SECRET client secret
    NETATMO_REFRESH_TOKEN refresh token (only needed for the first start or to re-authorise)
  4. Add a weather station node, create a Netatmo account in it (the defaults already point to the variables above) and deploy.

The fields of the account node contain only references like ${NETATMO_CLIENT_SECRET}, so the secrets never end up in your flow file or in flow exports. If you type a secret directly into a field, the node logs a warning.

Docker, balena and similar

Set the variables in the container environment, e.g. as fleet or device variables on balena or under environment: in a compose file. Make sure the token file lies on a persistent volume. By default it is <userDir>/netatmo/tokens-<node id>.json; set an absolute path if your user directory is not persistent.

Several Node-RED instances

A token chain must be used by one Node-RED instance only. Two instances refreshing the same chain invalidate each other's tokens. Use one Netatmo app (or at least one generated token) per instance.

Nodes

weather station

Triggered by any input message, or by its own timer (Poll every, 0 = only on input).

Setting Meaning
Station MAC address of the main station (70:ee:50:...) or ${VAR}. Empty: all stations of the account
Include favourite stations also return stations marked as favourites
Output API response or One message per module

API response (default): msg.payload is the response exactly as Netatmo delivers it:

{
  "body": {
    "devices": [{
      "_id": "70:ee:50:00:00:01", "type": "NAMain", "station_name": "My station (Indoor)",
      "reachable": true, "wifi_status": 39,
      "dashboard_data": { "time_utc": 1795442972, "Temperature": 23.9, "CO2": 1145, "Humidity": 47,
                          "Noise": 36, "Pressure": 1005.5, "AbsolutePressure": 954.3, "...": "..." },
      "modules": [{
        "_id": "02:00:00:00:00:02", "type": "NAModule1", "module_name": "Outdoor",
        "battery_percent": 65, "rf_status": 39, "reachable": true,
        "dashboard_data": { "time_utc": 1795442947, "Temperature": 2.8, "Humidity": 91, "...": "..." }
      }]
    }],
    "user": { "...": "..." }
  },
  "status": "ok", "time_exec": 0.08, "time_server": 1795443481
}

One message per module: the main station and each module as a separate message:

{
  "topic": "My home/Outdoor",
  "payload": { "time_utc": 1795442947, "Temperature": 2.8, "Humidity": 91, "min_temp": 1.6, "...": "..." },
  "netatmo": {
    "module_id": "02:00:00:00:00:02", "module_name": "Outdoor", "type": "NAModule1",
    "reachable": true, "battery_percent": 65, "battery_vp": 5362, "rf_status": 39,
    "station_id": "70:ee:50:00:00:01", "station_name": "My station (Indoor)",
    "home_id": "...", "home_name": "My home", "place": { "...": "..." }
  }
}

Values and units are those of the Netatmo API (time_utc in Unix seconds). Module types: NAMain indoor station, NAModule1 outdoor, NAModule2 wind, NAModule3 rain, NAModule4 extra indoor module.

Netatmo stations upload about every 5 to 10 minutes; polling more often than once a minute brings no new values. Netatmo allows 500 requests per hour and user.

netatmo api

Calls https://api.netatmo.com/api/<endpoint>. Parameters come from the node configuration (JSON) merged with msg.params (or an object in msg.payload). msg.endpoint overrides the endpoint. msg.payload of the output is the unchanged Netatmo response.

Example, temperature history of the last day in 30 minute steps:

{ "params": { "device_id": "70:ee:50:00:00:01", "scale": "30min", "type": "Temperature",
              "date_begin": 1795360000, "optimize": "false" } }

Errors

Network and API errors are thrown to Node-RED, so a catch node receives them; msg.error holds message, code and status. If the authorisation fails for good (refresh token revoked or used by another instance), the node status turns red: generate a new refresh token, set it as NETATMO_REFRESH_TOKEN and restart or redeploy.

Example

Menu → Import → Examples → node-red-contrib-netatmo-cloud contains a ready-made flow.

Migrating from a hand-made OAuth2 flow

If you kept the token in a JSON file with an http request / file node flow, you can point the Token file setting to that file: any JSON file with a refresh_token field is accepted, and the chain continues without a new token. Remove the old flow in the same deploy, otherwise both refresh the same chain.

Development

npm install
npm test

The tests run against a fake Netatmo server that rotates refresh tokens like the real one, and load the nodes into a real Node-RED runtime with node-red-node-test-helper.

Kurzfassung auf Deutsch

Node-RED-Nodes für die Netatmo-Cloud mit eingebauter OAuth2-Token-Verwaltung: kein separater Authentifizierungs-Flow mehr nötig. App auf dev.netatmo.com anlegen, mit dem Token-Generator ein Refresh-Token erzeugen und NETATMO_CLIENT_ID, NETATMO_CLIENT_SECRET und NETATMO_REFRESH_TOKEN als Umgebungsvariablen setzen (auf balena als Flotten- oder Gerätevariablen). Der Node speichert das sich bei jedem Refresh ändernde Token selbst auf dem persistenten Speicher. Ausgabe: die Netatmo-Antwort unverändert oder eine Nachricht pro Modul.

License

Apache License 2.0, see LICENSE.

Not affiliated with or endorsed by Netatmo. Netatmo is a trademark of its owner.

Node Info

Version: 1.0.0
Updated 4 days ago
License: Apache-2.0
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Nodes

  • netatmo-account
  • netatmo-weather
  • netatmo-api

Keywords

  • node-red
  • netatmo
  • weather station
  • oauth2
  • co2
  • temperature
  • humidity
  • home automation

Maintainers