logo elektroda
logo elektroda
X
logo elektroda

OpenBeken setup for Tuya pilot-wire relay: flashing, GPIO mapping, Home-Assistant integration

User question

setup openBK for tuya pilot wire

Artificial Intelligence Response

Direct answer to the question

• Flash OpenBeken (OpenBK) onto the Tuya pilot-wire module, then assign the two GPIOs that drive the positive and negative half-wave outputs to the dedicated “Diode _R_B” driver in OpenBK.
• After saving the template the pilot-wire channel (Ch 1 by default) accepts the following values:
 0 = Comfort, 1 = Eco, 2 = Frost-protection, 3 = Off.
• Verify the wave-shapes with a multimeter/oscilloscope, then expose the channel through MQTT or HTTP for Home-Assistant or any other automation platform.


Detailed problem analysis

1 Pilot-wire (fil-pilote) principle
• A single control conductor referenced to Neutral conveys four main heater orders by inserting specific half-wave patterns into the 50 Hz mains:
 – No signal (open) → Comfort 
 – Full sine (both half-waves) → Eco (-3 … -4 °C)
 – Only negative half-wave → Frost-protection (≈ 7 °C)
 – Only positive half-wave → Off
• Most Tuya pilot-wire relays implement two opto-triac channels (sometimes relays + diodes) that can be driven independently to create the three composite wave-forms.

2 Hardware used by Tuya
• Main RF/MCU module: BK7231T, BK7231N, WB3S, CB3S – fully supported by OpenBK ≥ 1.17.0.
• Pilot-wire power stage: two opto-triacs (e.g. MOC3063) feeding a power triac or two SSRs plus steering diodes.
• Exposed test pads: TX/RX, 3 V3, GND and CEN (reset/boot-strap).

3 Firmware driver inside OpenBK
• “Diode_R_B” (aliases: DIODES_R_B, PilotWire4Mode) → consumes two GPIOs:
  • GPIO_A → Role Diode_R_B_A (positive half-wave)
  • GPIO_B → Role Diode_R_B_B (negative half-wave)
• OpenBK internally creates one integer Channel (default Ch 1) whose value encodes the 4 modes shown above.
• Swapping the two roles inverts “Off” and “Frost”; this is the first thing to try when the modes look reversed.

4 Signal timing
OpenBK automatically synchronises to the 50 Hz zero crossings; you do not need external zero-cross hardware for typical Tuya boards because the opto-triacs are zero-cross versions.


Current information and trends (Q2 2024)

• Tuya-cloudcutter (v0.8+) now supports BK7231x pilot-wire devices OTA if factory firmware ≤ 1.1.9; this avoids soldering in ~70 % of cases.
• OpenBK added Web-installer (USB-Web-serial) for Chrome/Edge, easing serial flashing on Linux/Mac.
• A community template database (GitHub → obk-templates.json) auto-detects many pilot-wire boards and pre-assigns the Diode_R_B pins.
• MQTT-AutoDiscovery for Home-Assistant is built-in since OpenBK 1.16 – the heater shows up as climate.* without YAML.
• Matter/Thread support is on the roadmap but experimental.


Supporting explanations and details

Pilot-wire timing matrix:

Value Positive HW Negative HW Resulting mode
0 0 0 Comfort
1 1 1 Eco (both)
2 0 1 Frost (– half)
3 1 0 Off (+ half)

(1 = channel energised, 0 = idle)

Example console commands:

setChannel 1 0 // comfort
setChannel 1 1 // eco
setChannel 1 2 // frost-protection
setChannel 1 3 // off

Home-Assistant manual YAML (if you do not use Auto-Discovery):

mqtt:
climate:
- unique_id: heater_lr
name: "Living-Room Pilot-Wire"
modes: ["heat","off"]
preset_modes: ["comfort","eco","away","off"]
mode_state_topic: "stat/pilotwire/Ch1"
mode_command_topic: "cmnd/pilotwire/Ch1"
mode_command_template: >
{% if value == "heat" %}0{% else %}3{% endif %}
preset_mode_state_topic: "stat/pilotwire/Ch1"
preset_mode_command_topic: "cmnd/pilotwire/Ch1"
preset_mode_command_template: >
{% set map={'comfort':0,'eco':1,'away':2,'off':3} %}
{{ map[value] }}
preset_mode_value_template: >
{% set map={'0':'comfort','1':'eco','2':'away','3':'off'} %}
{{ map[value] }}

Ethical and legal aspects

• Mains-voltage manipulation: European low-voltage directives (LVD 2014/35/EU) and EMC compliance may be voided after modification; recertification is needed for commercial use.
• Warranty and Tuya cloud T&C are broken once reflashed.
• Data privacy improves (local control, no cloud).
• Always disconnect from mains, use an isolating transformer for bench tests, and respect national electrical codes (NF C 15-100 in France).


Practical guidelines (best practice)

  1. Preparation
     • Scan PCB for template in community DB – may spare you pin-hunting.
     • Backup original firmware via bk_writer --dump.

  2. OTA (Cloudcutter) procedure
     • Phone in AP mode, feed device Internet, run exploit script.
     • If exploit fails → fall back to UART.

  3. Serial flashing quick-flow
     a) 3 V3 ↔ VCC, GND ↔ GND, TX/RX cross.
     b) Hold CEN low, power up, release → chip in boot loader.
     c) ./uartprogram OpenBK7231*.bin -b 115200 -w.

  4. First boot
     • Connect to OpenBK_xxxxxx AP → 192.168.4.1 → Wi-Fi creds.
     • Upgrade to newest build via Web-OTA.

  5. Configuration
     • Config → Configure Module → assign Diode_R_B_A/B.
     • Optionally assign status LED (LED_i) and push-button (Button).

  6. Validation
     • Oscilloscope between pilot wire and Neutral: confirm correct half-wave.
     • Swap GPIO roles if wrong polarity.

  7. Integration
     • Config → MQTT → broker, topic base.
     • Enable setOption73 1 (HA auto-discover).

Common pitfalls & fixes
• Modes inverted → swap A/B roles.
• Relay chattering → wrong GPIO type, use “Relay (i)” not “PWM”.
• HA entity missing → retain flag off, then restart HA.


Possible disclaimers or additional notes

• Some heaters support 6-order pilot-wire (Comfort −1 °C / −2 °C). OpenBK night-builds already expose values 4 & 5; hardware must support triac phase gating.
• Very small Tuya modules (CB2S) use 2 mm pitch pads – soldering is delicate.
• OTA exploits may be patched in new Tuya firmware revisions; keep a USB-UART dongle handy.


Suggestions for further research

• Evaluate open-source zero-cross AC wave-shaping libraries to add 6-order modes.
• Investigate Matter over Wi-Fi integration once the OpenBK Matter branch stabilises.
• Look at NRF24L01 pilot-wire bridges for multi-room synchronised heating as a complement to Wi-Fi.
• Monitor OpenBK GitHub issues: many templates for brand-new Legrand/Möhlenhoff pilot-wire relays appear weekly.


Brief summary

Flashing OpenBeken onto a Tuya pilot-wire module, assigning its two output pins to the built-in “Diode_R_B” driver, and mapping channel values 0-3 to Comfort/Eco/Frost/Off lets you reproduce the four canonical pilot-wire commands locally, cloud-free, and fully automatable via MQTT or HTTP. OTA flashing with CloudCutter now covers most BK7231 devices; serial flashing remains the universal fallback. Verify half-wave polarity, follow mains-safety rules, and you have a robust, open-source heating controller ready for seamless Home-Assistant integration.

Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.