Novi Bezradychi · railway grid line · queue 1.1
A mains sensor for the Dom1 switchboard
Three meters sit on the incoming phases before the transfer switch, and the ESP32 runs on the inverter. So the sensor can tell a grid outage from a lost connection. Below is the panel built from the model, with every install step shown on it.
- phases watched
- L1 · L2 · L3
- errors in the build
- 0
- DIN modules
- 18/24
- inside the box
- ~37 °C
Install plan
Each step highlights its parts on the panel. Marked steps are live or next to live parts and are done by the electrician.
Before the visit: firmware and addresses on the bench
P1. Flash the ESP32 on the bench
- Connect the ESP32 to a laptop over USB (no 230 V on the bench yet).
- Create secrets.yaml from secrets.example.yaml (panel-room Wi-Fi, OTA password, two Healthchecks links).
- Flash esphome/pzem-set-address.yaml with esphome run.
P2. Set the PZEM addresses one at a time
- Bench: extension lead with a 30 mA RCD, PZEM in a closed box, L/N terminals covered. One meter at a time.
- TTL side: 3V3, GND, ESP32 TX → meter RX, meter TX → diode → ESP32 RX.
- Enter the new address on the page: A1 → L1 = 1, A2 → L2 = 2, A3 → L3 = 3.
- Unplug, mark the meter (phase and address), next one.
P3. Flash the working config
- Run esphome/dom1-sensor.yaml with esphome run over USB.
-
S1 electrician
Isolate the supply and prove it dead
- Switch off the grid main breaker in the Dom1 panel (SEZ PR63 C32 3P “city”). Its line-side terminals stay live — do not touch. Generator off; leave the Hager SFT 340 switch to the electrician.
- Switch off the inverter group breaker (C16 1P): the inverter output is live even without grid!
- Hang a “Do not switch on — work in progress” tag, lock the panel or tape the breakers.
- With a two-pole voltage tester: prove the tester on a known source → check for no voltage L1–N, L2–N, L3–N, L1–L2, L2–L3, L1–L3, L–PE at the tap point and on the inverter group → prove the tester again.
- No voltage at any point we will work on (tester good before and after).
-
S2
Mount the box and rails
- Surface box 2 × 12 modules, IP40, plastic: on the wall next to the Dom1 panel, cable entries at the top.
- Conduit from the panel to the box no longer than 3 m (the tap is unprotected at its start).
- Box level, fixings hold, cover needs a tool to open.
-
S3
Top row: breakers, neutral terminals, power supply
- QF1 (3P C2) feeds the meters; QF2 (1P C2) feeds the power supply.
- Two separate N terminals: grid before ATS and inverter output. NO bridge between them.
- G1 — Mean Well HDR-15-5 on the right.
- Rail labels: “grid N”, “inverter N”.
-
S4
Bottom row: meters, low-voltage terminals, ESP32
- PZEM boards on DIN PCB holders: L1, L2, L3 left to right, 230 V terminals up.
- 3V3 / GND / TX / RX terminal block and ESP32 on the right, apart from the 230 V terminals.
- Gap between the PZEM boards and the ESP32; PZEM 230 V terminals can't reach the low-voltage wires.
-
S5
Mains to the meters: L1/L2/L3 and N
- From QF1: L1 brown, L2 black, L3 grey; N blue.
- PV-3 1.0 mm² with ferrules, screws torqued to the maker's value.
- Each PZEM on the phase written on it and in the config.
- Continuity: each PZEM L terminal ↔ its breaker pole; all three N ↔ “grid N”.
-
S6
Power supply from the inverter
- QF2 → power supply L, “inverter N” → power supply N.
- Continuity: power supply N does NOT ring through to “grid N”.
-
S7
Low voltage: ESP32 power, bus, diodes
- PSU +V → ESP32 VIN, −V → GND. ESP32 3V3 and GND → terminal block → VCC/GND of each PZEM.
- ESP32 TX (GPIO17) → TX terminal → RX of all three PZEM.
- TX of each PZEM → cathode of a 1N4148 (band to the meter), the three anodes → RX terminal → GPIO16.
- NV 0.5 mm² 600 V wire, not Dupont jumpers; keep the harness apart from 230 V wires.
- Multimeter: diode conducts from RX to meter TX, not back. 3V3 not shorted to GND.
-
S8 electrician
Checks before energising
- Visual: all screws, ferrules, phase marking, PZEM terminal covers.
- 500 V insulation tester on the tap cables (meters and PSU disconnected!): ≥ 1 MΩ between L1, L2, L3, N.
- Insulation ≥ 1 MΩ; record it.
-
S9 electrician
Connect the taps in the Dom1 panel
- Grid: load terminals of the SEZ PR63 C32 3P grid main, before the ATS contactor CNN 32 — where only the railway line is present.
- Inverter: the C16 1P inverter output group.
- The electrician confirmed: grid point before the ATS, inverter point after the inverter.
-
S10 electrician
Energise and verify phases
- Remove tags, switch on the inverter group, then QF2: ESP32 boots, Healthchecks “link” is green.
- Switch on the grid main, then QF1: three voltages on the ESP32 page.
- Multimeter L1–N, L2–N, L3–N at the PZEM terminals — matches its phase reading (±2 V).
- All three phases within 207–253 V and match the multimeter phase by phase.
-
S11
Test the alarms
- Switch QF1 off: within ~30 s “L1, L2, L3 lost”, ESP32 stays up, Healthchecks “grid” turns red.
- Switch QF1 on: the alarm clears.
- Turn off the router or Wi-Fi: within 180 s Healthchecks “link” turns red.
- Both alerts arrived and differ: “grid” ≠ “link”.
-
S12
Close the box and document
- Cover on, diagram inside the door, QF1/QF2 labels, “Dom1 mains sensor”.
- Photo of the box into the house project folder.
- Cover closed, boards reachable only with a tool.
What stops the install
Typical mistakes. The engine passes none of them: each one is an error with an explanation, not a warning. Engine output is in Ukrainian.
Swapped phases: L1 and L2 crossed at the meters
A1: підписаний L1, а підключений до L2. У конфігу ESPHome цей модуль буде «L1», а насправді міряє L2. Сигнал «зникла L1» прийде про іншу фазу, і електрик шукатиме несправність не там.
Power supply fed from the grid instead of the inverter
G1 живиться від мережа до АВР. Коли зникне світло, згасне і ESP32: замість «зникла фаза» прийде тільки «немає зв'язку», а мережа і щит стануть нерозрізненні. Блок живлення — тільки від виходу інвертора.
Meters wired after the transfer switch
A1 підключений після АВР. Після АВР напруга є і тоді, коли УЗ без світла: АВР перемикає на резерв. Датчик не побачить аварію. PZEM підключають до вводу УЗ до контактора АВР.
1.5 mm² tap off the C32 main breaker
T1: 1.5 мм² не витримає КЗ до автомата датчика. Від КЗ це відгалуження захищає вводний uz:C32. Він пропускає до 35 000 А²·с а провід 1.5 мм² витримує k²S² = 29 756 А²·с — ізоляція розплавиться раніше ніж автомат вимкне. Потрібно ≥ 2 5 мм².
Three meter TX lines tied without diodes
TX кількох PZEM з'єднані напряму: A1, A2, A3. Виходи TX модулів — оптрони з підтяжкою. Напряму на спільній шині модуль, що мовчить, тримає «1», а той, що відповідає, тягне в «0»: сигнали б'ються, Modbus дає збої. На TX кожного модуля — діод 1N4148 (катод до модуля), шина RX підтягнута до 3,3 В.
Grid N bridged to inverter N
Нейтралі мережі й інвертора з'єднані в щитку датчика. N до АВР і N виходу інвертора мають бути на різних клемах. Перемичка між ними обходить реле нейтралі інвертора і ПЗВ резервних груп: струм N піде в чужу лінію.
Dupont jumpers next to 230 V
S1: ізоляція проводу невідома поруч із 230 В. Слабкострумові дроти (Dupont-перемички, дріт від кабелю витої пари) лежать в одному щитку з фазою. Ізоляція кожного проводу в щитку — не нижче 300 В (краще НВ/ПВ-3 450–600 В), інакше пробій з'єднає 230 В з ESP32.
12-module enclosure
Не вміщається: потрібно 18 модулів, у щитку 12. Компоненти A1, A2, A3, XS1, U1 не мають місця на рейці. Плати PZEM і ESP32 на DIN-тримачах займають по 2–3 модулі, тому щиток на 8–12 модулів замалий: потрібен 2 × 12 (24 модулі) або більший.
What the engine checked
Calculations and assumptions for this build. There are no errors, so only notes and warnings are listed. Engine output is in Ukrainian.
calc QF1 (C2) селективний з C32 до ~160 А КЗ
При перевантаженні вимкнеться тільки QF1. При КЗ понад ~160 А (миттєве спрацювання C32 від 5·In) можуть вимкнутися обидва — для кола датчика це прийнятно.
ДСТУ EN 60898-1, характеристика C: 5–10·In
calc QF2 (C2) селективний з C16 до ~80 А КЗ
При перевантаженні вимкнеться тільки QF2. При КЗ понад ~80 А (миттєве спрацювання C16 від 5·In) можуть вимкнутися обидва — для кола датчика це прийнятно.
ДСТУ EN 60898-1, характеристика C: 5–10·In
calc U1: падіння на живленні 5 В — 0.28 % при 0,5 А
ESP32 DevKit потребує на VIN ≥ 4,5 В (стабілізатор AMS1117 має запас ~1,1 В).
calc Плати PZEM — під напругою мережі
Не торкатися плат при ввімкненому QF1; кришку щитка знімати тільки після відключення QF1 і вводу. Розв'язка TTL — оптронна у самому PZEM (паспорт виробника не дає її номінал, тому USB до ESP32 підключати тільки при вимкненому QF1).
calc 1N4148: «0» на RX ≈ 0,6–0,7 В
Поріг «0» ESP32 — 0,25·VDD ≈ 0,8 В: запас малий, але робочий. Якщо будуть збої — замінити на Шотткі BAT85 (Vf ≈ 0,4 В).
Espressif ESP32 datasheet (VIL)
calc Живлення 5 В: потрібно 0.52 А пікових, G1 дає 2.4 А
ESP32 з Wi-Fi — до 0,5 А в піку, оптрони трьох PZEM від 3V3 — ~15 мА.
Mean Well HDR-15 datasheet
calc U1: USB і VIN разом
Перепрошивати по USB при вимкненому QF2 або через USB-кабель без живлення: на частині DevKit немає діода між USB 5 В і VIN.
calc Зайнято 18 з 24 модулів (75%)
Запас ≥ 20 % місця — під другий комплект або реле. Щиток на 8–12 модулів для цього складу замалий.
ДСТУ EN 61439-1 (запас місця — практика)
calc Нагрів: 3.1 Вт, усередині ~37 °C при 35 °C у щитовій
Перегрів 2.4 K = P / (k·A), k = 5.5 Вт/(м²·K), A = 0.24 м². Найслабше місце — A1, A2, A3 (до 60 °C).
ДСТУ EN 61439-1 (метод IEC 60890, спрощено)
calc Як датчик бачить пропажу фази
PZEM живиться від своєї фази і міряє від 80 В. Нижче 80 В модуль замовкає — це і є «зникла фаза», якщо відповіді немає довше 30 с, а ESP32 на інверторі живий. Перекос рахується за модулями напруг (max відхилення від середнього), це наближення до коефіцієнта зворотної послідовності EN 50160.
ДСТУ EN 50160
What the sensor reports
Limits follow EN 50160. The grid alarm and the link alarm are separate Healthchecks checks, so they can't be confused.
| Phase lost | meter silent for over 30 s |
|---|---|
| Voltage out of range | 207–253 V |
| Frequency out of range | 49.5–50.5 Hz |
| Phase unbalance | ≤ 2 % |
| No link to the panel | 180 s |
Where to buy
Prices and stock checked on 2026-11-14. Nothing is bought until the owner says yes. Item names are in Ukrainian.
| Item | Ukraine | Price | Stock | Abroad |
|---|---|---|---|---|
| Вимірювач PZEM-004T v4.0 100 А з трансформатором струму × 3 | Prom.ua | 395 UAH | немає | AliExpress |
| Плата ESP32 DevKit 30 pin з CH340C | Prom.ua | 245 UAH | в наявності | AliExpress |
| Блок живлення Mean Well HDR-15-5 на DIN-рейку | meanwell.kiev.ua | 524 UAH | в наявності | AliExpress |
| Автоматичний вимикач 3P C2, 6 кА | 220volt | 1,024 UAH | в наявності | — |
| Автоматичний вимикач 1P C2, 6 кА | 220volt | 343 UAH | в наявності | — |
| Щит навісний пластиковий 24 модулі (2×12), IP40 | 220volt | 926 UAH | в наявності | — |
| Діоди 1N4148 (10 шт.), варіант — Шотткі BAT85 × 10 | Mini-Tech | 1 UAH | в наявності | — |
| Тримач друкованої плати на DIN-рейку × 4 | arduino.ua | 53 UAH | в наявності | AliExpress |
| Провід ПВ-3 2,5 мм² (коричневий, чорний, сірий, синій) × 4 | Prom.ua | 32 UAH | в наявності | — |
| Провід ПВ-3 1,0 мм² × 5 | Епіцентр | 15 UAH | в наявності | — |
| Провід НВ 0,5 мм² 600 В або МГШВ 0,5 × 5 | Prom.ua | 6 UAH | в наявності | — |
| Кабель ПВС 3×1,5 × 3 | Епіцентр | 73 UAH | в наявності | — |
| Клеми на DIN, наконечники НШВІ, гофра 16 мм | Prom.ua | 7 UAH | в наявності | — |
What we don't know yet
- точку до АВР підтверджує електрик на місці
- струм КЗ на вводі ≤ 6 кА (сільська лінія, не міряли)
- номінал групи C16 уточнює електрик
- Where the Hager SFT 340 grid/generator switch sits relative to the ATS in the Dom1 panel — the electrician confirms the pre-ATS tap point on site.
- The pilot does not fit the PZEM current transformers: voltage and frequency are enough to tell presence and quality of mains.
- Linking to the outage schedules (outages.py) is the next step once the sensor works.
The electrician's brief (Word, Ukrainian) is in the elecgen project: docs/TZ-ELECTRICIAN-DOM1.docx. The owner hands it over.