@offgridgalaxy/node-red-victron-tuya 0.7.0
Tuya Wi-Fi lights, smart plugs (incl. energy monitoring), power strips, dimmers and thermostats as Victron Venus OS (GX) switches with two-way sync, controlled locally (no cloud)
@offgridgalaxy/node-red-victron-tuya
Makes a Tuya Wi-Fi device (Smart Life / Tuya Smart app) — a light, smart plug, power strip, dimmer or thermostat — appear as a switch on a Victron GX device (Venus OS) and keeps the two in sync both ways. One node per device, nothing to wire.
- Local control only. The node talks to the device directly on your network (Tuya protocol 3.1–3.5 via tuyapi). It never uses the Tuya cloud for control.
- No Tuya developer account needed. One QR-code login in the Smart Life app reads all your devices and their keys into a Smart Life account config node. Every device node then just picks its device. Or you can enter the ID and key yourself.
- Changes made in the app, with a remote or a wall switch show up on the GX straight away: the device pushes its state.
- If the device is unreachable, the GX shows an output fault. It reconnects by itself.
- A Tuya Master Switch node gives one GX switch for several devices, such as all the lights in a cabin.
Install
On a GX device with Venus OS Large, or any Node-RED that can reach the GX D-Bus: in Node-RED's menu choose
Manage palette → Install and search for node-red-victron-tuya. Or from a shell:
cd ~/.node-red # on Venus OS Large: /data/home/nodered/.node-red
npm install @offgridgalaxy/node-red-victron-tuya
Then restart Node-RED. The shared library @offgridgalaxy/victron-virtual-switch-core is installed automatically.
Moving from the earlier node-red-contrib-victron-tuya tarball? Remove it (and victron-virtual-switch-core) in
the palette manager first: both packages provide the same nodes, and Node-RED won't load them twice. Flows, the
account's keys and the GX state are kept.
Supported devices
Each device type is handled by a profile:
| Profile | Devices | On the GX |
|---|---|---|
| RGB + white light (DP 20 + 51) | Ceiling or table lights with a separate RGB part and white part (category xdd) |
RGB colour wheel + white colour-temperature wheel; both can be on at once |
| Standard Tuya light (DP 20–24) | Most bulbs, strips and downlights | Colour wheel (if the light has colour) + white output (colour temperature, dimmer or switch, depending on the light) |
| Smart plug / power strip (DP 1–6) | Wi-Fi outlets, power strips and relay switches (categories cz, pc, kg) |
One on/off switch per socket |
| Smart plug with energy monitoring ¹ | Plugs that measure power: DPs 17–20 (most), 4–6 or 6–9 (older models) | One on/off switch per socket; power, voltage, current and energy on the node output and status |
| Dimmer (DP 1 + 2) ¹ | Wall and inline dimmers (categories tgq, tgkg) |
One dimmable switch |
| Thermostat / heater (DP 1–3) ¹ | Thermostats, panel heaters, water heaters with power on DP 1, setpoint on DP 2 and room temperature on DP 3 (categories wk, qn, rs) |
An on/off switch + a temperature setpoint showing the room temperature |
¹ Built from the published data point layouts of these devices (make-all/tuya-local), not yet tested on real hardware. If one doesn't behave, send the line the editor's Test button shows.
- Energy monitoring: these plugs rarely report readings on their own, so the node asks for them every
Readings seconds (default 15; 0 = only what the plug reports).
energyis the plug'sadd_elevalue in kWh; on many plugs it is the energy since the previous report rather than a running total. - Dimmers and thermostats are recognised by their Tuya category, which comes with devices picked from a Smart Life account. Devices entered by hand: pick the profile yourself.
- Thermostats store temperatures in whole, half or tenth degrees depending on the model (21 °C can be 21, 42 or
210). Test picks the Device unit from the readings; check the GX shows the setpoint you expect. Celsius only.
Modes and presets (DP 4 and up) vary by model: send them raw with
{ dps: { "4": "..." } }. Not supported: heaters whose DP 1 is something other than power (e.g. Beca BHP-6000) and models with a different layout.
The editor's Test button reads the light's data points and picks the profile. Some lights leave data points out
of their status reply (the RGB + white lights often omit DP 51). The node then asks for them explicitly, and with
the QR login it also uses the product's data point list from Tuya. Other device types
(fans, covers, …) can be added as new profiles. See lib/profiles/.
Setup
- Add a Tuya Switch node (Victron Energy category).
- Account. The first time, press the pencil next to Account to add a Smart Life account. Enter the User code from the app (Me → Settings → Account and Security → User Code), press QR code, scan it with the app and confirm. All your devices and their keys are read at once. Click Add. Later device nodes reuse the same account: no new scan.
- Device. Pick the device from the list. This fills in its ID and picks the profile. Without an account, enter the device ID and local key yourself.
- IP address. Press 🔍 to search the network, or enter the IP yourself. Give the device a fixed DHCP lease on your router. The search listens for lights announcing themselves (UDP 6666/6667). It also asks protocol 3.5 lights to identify themselves (UDP 7000), because those stay quiet until asked. It only works when Node-RED is on the same network segment as the light, for example on the GX, not in a VM or WSL.
- Press Test, check the profile and output names, then deploy.
About the QR login
The QR login uses Tuya's "device sharing" login (the same one Home Assistant's Tuya integration uses). It needs a client ID registered with Tuya. The default is Home Assistant's, the only one known to work, and you can change it under Advanced. The node:
- logs in, reads the device list, and logs out again: no cloud tokens are kept
- stores the device list in the flow, and the keys in Node-RED's encrypted credentials (not included when you export the flow)
You only need to fetch again after adding a new light to the app, or re-pairing one. Re-pairing changes the key; after a refresh and a deploy, every light node using the account gets the new key.
If Tuya ever blocks this login, enter the key yourself instead. Control is not affected either way.
One connection only
Many Tuya devices accept only one local connection. Disable any other local integration for the same light, such as node-red-contrib-tuya-devices or Home Assistant's local Tuya, or this node can't connect. The editor's Test button reuses the deployed node's connection.
Input
msg.payload |
Effect |
|---|---|
true / false / 1 / 0 / "toggle" |
switch the light on or off (restoring the last colour mode) |
{ rgb: {on, hue, saturation, brightness, color}, white: {on, brightness, kelvin} } |
RGB + white profile |
{ on, brightness, kelvin, color: "#rrggbb", mode: "white" | "colour" } |
standard profile |
{ on } or { socket: 2, on: true } |
smart plug / power strip (all sockets, or one) |
a number 0–100, or { on, brightness } |
dimmer: brightness in % (0 = off) |
a number in °C, or { on, setpoint } |
thermostat: setpoint |
{ dps: { "20": true } } |
send raw Tuya data points, e.g. a plug's power-on behaviour: { dps: { "38": "memory" } } |
RGB + white lights: one part at a time
Set msg.topic to rgb or white (changeable in the node) and the payload controls only that part:
msg.topic |
msg.payload |
Effect |
|---|---|---|
rgb / white |
true / false / 1 / 0 / "toggle" |
switch just that part |
rgb / white |
2–100 |
that part's brightness, and switch it on (0 switches it off) |
rgb |
{ on, hue, saturation, brightness, color } |
RGB part |
white |
{ on, brightness, kelvin } |
white part |
A message without a matching topic controls the whole light, as above.
Output
RGB + white lights have two outputs, RGB and white. Each sends its part's state only when that part changes:
msg.topic = 'rgb' // or 'white': the part, so the message works as input to a light
msg.payload = { on, hue, saturation, brightness, color } // white: { on, brightness, kelvin }
msg.light = 'Galley table'
After upgrading from 0.1.2 or earlier, open the node and click Done to get the two outputs. Until then it keeps one combined output. Other profiles have one output:
msg.payload = { ... } // the device's state, in the same shape as the input
// energy plugs add power (W), voltage (V), current (A), energy (kWh);
// dimmers: { on, brightness }; thermostats: { on, setpoint, temperature }
msg.dps = { '20': true, '51': '...' } // raw data points
msg.source = 'device' | 'venus' | 'input'
Tuya Master Switch
One switch on the GX that controls several Tuya Switch nodes at once, such as all the lights in a cabin.
- Layout: One switch, or RGB + white (two switches) like an RGB + white Tuya Switch node: an RGB colour wheel for the members' RGB parts and a white colour-temperature wheel for their white parts. Each device then chooses which of the two switches it joins. For standard lights, the RGB switch means colour mode and the white switch white mode.
- Control (one switch): choose what the GX switch offers: On/off, On/off + dimmer, + RGB colour, or + white temperature (CCT). Each member gets what it supports: colour goes to colour lights, temperature to white lights.
- Devices: add as many as you need, either Tuya Switch nodes or devices from a Smart Life account that you never want to control on their own (enter their IP or press 🔍). For RGB + white lights, choose RGB + white, RGB only or White only.
- State: the master is on while any member is on, counting only each member's selected part. One tap switches everything off. Its brightness, colour and temperature on the GX show the first member that is on.
- Shared connections: several masters can include the same device. They share one connection to it.
- One connection: many Tuya devices accept only one local connection, so the master always goes through a device's Tuya Switch node when one is deployed. It connects to account devices itself only while they have no node, and hands the connection over automatically if you add one later. To show only the master on the GX, set the member nodes' Show in to Hidden.
Input: true/false/"toggle" or { on, brightness, hue, saturation, kelvin, color }. Output:
{ on, brightness, …, members: [{ name, part, on, online }] } on every change.
Migrating from node-red-contrib-tuya-devices + virtual switches
Disable or delete the old tuya-devices nodes for this light, the two victron-virtual-switch nodes and
the function nodes between them. Then add one Tuya Switch node. The local key from your old setup works.
Not affiliated with or endorsed by Victron Energy or Tuya. Victron, Venus OS and GX are trademarks of Victron Energy BV; Tuya and Smart Life are trademarks of Tuya Inc.