I use M-Track Reloaded, an ESP8266 – Tasmota – Node-RED – MQTT – Raspberry Pi 4 home-made solution, to control my vintage Märklin M-Track accessories over WiFi. The next step is wireless contact and occupancy detection to replace the classic Märklin contact and switching tracks, and this episode covers a custom sensor PCB plus the Node-RED flow that turns raw sensor messages into a working block system. It is all going to be about wires — or rather, about avoiding them.
Quick answer: The sensor PCB reports contact events over WiFi, Tasmota pushes them through MQTT, and Node-RED converts each message into occupancy state per block section. The same signal-based approach scales beyond trains: no camera, no PIR lens, just radio and a flow.
How signal-based occupancy differs from PIR and cameras
Three sensor families dominate presence detection, and they fail in different ways. PIR sensors detect moving heat: they are cheap and tiny, but a person sitting still reads as an empty room, and pets or heaters trigger false positives. Cameras detect presence visually, including still subjects, and give you the richest data — at the cost of privacy concerns, bandwidth, and somewhere to store footage. The signal-based approach used here sits in between: each sensor node watches for a contact or signal change and reports that state over WiFi, so detection works in full darkness, involves no optics at all, and coverage is per-point — a block section, a doorway, a stair — rather than a whole-room cone.
For a model railway that per-point behavior is exactly what a block system needs: the layout is divided into sections, and knowing which section is occupied is what lets the automation slow trains, stop them before a rear-end collision, and switch accessories at the right moment.
What occupancy detection is actually good for
The railway use case is the demo, but the pattern transfers directly to home automation, and the same sensor-shopping logic from the top sensors and relays for Node-RED applies when you pick the detection hardware. Occupancy — as opposed to plain motion — is what makes lights that actually turn off: the flow holds the room “occupied” until every sensor reports vacant, so nobody gets plunged into darkness while sitting still. The same state drives HVAC setbacks per room, and a whole-home occupied/vacant signal is the backbone for heating schedules and presence-based security scenes. In Node-RED all of it is just MQTT topics flipping between two states, which is why the flow in the video looks almost boring — that is a feature.
One practical tip: debounce before you trust the state
Radio sensors occasionally drop or repeat a message, and a marginal contact can chatter. Before letting occupancy state drive anything, debounce it in Node-RED: feed sensor messages through a trigger node with an extend timer (or a delay node plus an RBE filter) so the state only flips after a stable reading — one to two seconds for contacts, longer for room presence. Log every state change to a debug tab for a day and you will see exactly which sensor chatters, before it has a chance to flash your lights at 3 a.m. If you are standing up the whole stack from scratch, the local smart home build guide shows how the ESP, MQTT, and Node-RED pieces fit together.
What the video covers
- 00:00 Intro
- 01:07 What has been done so far?
- 02:09 My Märklin block system and its limitations
- 05:01 Expected benefits of the track sensors
- 05:47 The custom PCBs
- 07:13 The software — the Node-RED flow for the prototype
- 13:24 Additional requirements
- 16:27 New version with additional functionality
- 18:54 Testing with accessories on the layout
- 22:30 Next steps and thanks
Auto-translated subtitles are available — French: how to enable them, German: wie man sie aktiviert. Project links: Tasmota documentation and Node-RED.
Occupancy without cameras — or with them?
Sensor-based occupancy is the privacy-friendly path: nothing in the room is watching, and the data never leaves your broker. If you would rather detect presence with a camera instead, take the time to compare security cameras on person detection and night vision specs before buying — and check whether footage can stay on local storage rather than a subscription cloud.
If you buy through links on the sites we recommend, we may earn a small commission.