Skip to content

Presence Sensor

github-actions[bot] edited this page Dec 1, 2026 · 8 revisions

LD2410 presence sensor

With the desktop app none of the software below is needed. Plug the radar into the wall-screen PC: the app finds it, switches the display with it and reports presence with its own sign-in. No Python, no token, no device ID. Set the timeout per device under Settings → Devices (Wall screen → The display). The Software sections are for hand-built browser kiosks.

Optional hardware accessory: an HLK-LD2410 (or LD2410B / LD2410C) 24 GHz radar presence sensor, wired to the kiosk via USB-UART. The sensor reports presence + distance to a body in front of it; Tiedenwerk uses this to:

  • POST presence state to /api/presence so the dashboard knows whether anyone's nearby
  • Turn the display off after N seconds of nobody-detected
  • Wake the display the moment someone walks up

Vastly nicer than a fixed sleep timeout. The display stays on while you're cooking and off while you're not.

Hardware

  • Sensor: HLK-LD2410, LD2410B, or LD2410C — €5-€15 from AliExpress / Banggood / Amazon. The B and C variants have additional features (Bluetooth config, slightly tighter detection patterns) but the base LD2410 is fine.
  • USB-UART adapter: any FTDI FT232 or CH340-based 3.3V USB-to-serial dongle. €3-€10. Make sure it's 3.3V — the LD2410 doesn't tolerate 5V.
  • Wiring: 4 pins on the LD2410 (GND, +5V, TX, RX) → 4 pins on the USB-UART (GND, VCC, RX, TX — note the swap, TX-to-RX and vice versa).

TODO: photo of the LD2410 wired to a USB-UART adapter

Place the sensor pointing at the area in front of the kiosk display, with line-of-sight (it sees through wood and drywall, not metal). Mount it 1-2m above the floor at chest height.

Software (Windows, without the app)

The Windows path uses the presence-sensor.py script from the repo's hardware/ folder. It opens the FTDI port, reads LD2410 reports, POSTs presence to /api/presence, and controls Windows display power via SendMessage(SC_MONITORPOWER).

Install Python deps

& "C:\Program Files\Python312\python.exe" -m pip install aio-ld2410 aiohttp pyserial

Configure

Edit the script's top-of-file constants or set env vars:

BAUD_RATE = 256000          # LD2410's default baud rate
DISPLAY_OFF_DELAY = 30      # seconds of no-presence before screen off
WATCHDOG_TIMEOUT = 30       # restart serial connection if no data this long
API_URL = env_var("URL", "http://localhost:3001").rstrip("/") + "/api/presence"
SENSOR_TOKEN = env_var("PRESENCE_TOKEN")

env_var("URL") reads TIEDENWERK_URL, and KINBOARD_URL when that is not set: the KINBOARD_* names from before the rename keep working until 2.0.

The sensor proves itself with a token. Make one in Settings → Devices → Presence sensor token → New token (the card appears once a screen has Presence sensor switched on). It is shown once; copy it then. Making a new one later replaces it, and the sensor is refused until it has the new one.

Or use the install-wide token: ./setup.sh --non-interactive adds PRESENCE_SENSOR_TOKEN to webapp/docker/.env and keeps an existing value on later runs unless you pass --force; on a manual install, generate one with openssl rand -hex 32. A family that has made its own token uses that one, and the server's no longer works for its screens.

Put the token in TIEDENWERK_PRESENCE_TOKEN on the kiosk. If you changed .env, recreate the webapp with your usual Docker Compose files; a container restart does not load changed environment variables. The API rejects sensor updates until a token is configured.

For a manual Windows run, set the token and Tiedenwerk address in PowerShell before starting the script:

$env:TIEDENWERK_PRESENCE_TOKEN = "the-same-random-value-as-the-webapp"
$env:TIEDENWERK_URL = "http://YOUR_TIEDENWERK_HOST:3001"

For the scheduled task below, save the token in the kiosk user's environment and sign out and back in before testing the task:

[Environment]::SetEnvironmentVariable("TIEDENWERK_PRESENCE_TOKEN", "the-same-random-value-as-the-webapp", "User")
[Environment]::SetEnvironmentVariable("TIEDENWERK_URL", "http://YOUR_TIEDENWERK_HOST:3001", "User")

The find_serial_port() helper auto-picks the FTDI port; if you have multiple USB-serial adapters, hardcode port = "COM3" (or whatever).

Run

The script takes the device ID as its first argument:

& "C:\Program Files\Python312\python.exe" C:\presence-sensor.py 680d36e4-a08e-4d69-bca9-4339fffcf017

Find the device ID:

  1. Open Tiedenwerk → Settings → Devices
  2. Toggle Presence sensor on for this device
  3. The 8-character truncated UUID appears below — click the copy button to get the full ID

Run hidden (so the user never sees a console)

Wrap the launch in a small VBS:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\Python312\python.exe"" C:\presence-sensor.py YOUR_DEVICE_ID", 0, False

Save as C:\run-presence-hidden.vbs. Window-style 0 = hidden.

Auto-start at logon

Register a Scheduled Task:

  • Trigger: At logon of the kiosk user
  • Action: wscript.exe with arguments C:\run-presence-hidden.vbs
  • General → Run as user, Run only when user is logged on, Run with highest privileges
  • Settings → Restart on failure (1 min, 3 attempts)

This is what the Kiosk-Windows-11-Mele-4C reference deployment uses.

Software (Linux, without the app)

Use the repo's kiosk/presence-sensor.py on a GNOME/Mutter kiosk. It reads the sensor at /dev/ttyUSB0 and controls display power through Mutter's D-Bus interface. Install aio-ld2410 and aiohttp in the Python environment used by the service. On another desktop, adapt its set_display_power() function to that desktop's display control command, for example:

def set_display_power(on):
    cmd = ["wlopm", "--on" if on else "--off", "*"]
    subprocess.run(cmd, check=False)

Then run via systemd:

# ~/.config/systemd/user/presence-sensor.service
[Unit]
Description=LD2410 presence sensor for Tiedenwerk
After=graphical-session.target

[Service]
EnvironmentFile=%h/.config/kinboard/presence-sensor.env
ExecStart=/usr/bin/python3 /home/kiosk/presence-sensor.py YOUR_DEVICE_ID
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

Create ~/.config/kinboard/presence-sensor.env with the following lines and make it readable only by the kiosk user (chmod 600):

TIEDENWERK_PRESENCE_TOKEN=the-same-random-value-as-the-webapp
TIEDENWERK_URL=http://YOUR_TIEDENWERK_HOST:3001

Enable: systemctl --user daemon-reload followed by systemctl --user enable --now presence-sensor.service. If the service was already running, use systemctl --user restart presence-sensor.service after changing the environment file.

How the data flows

LD2410 sensor (24 GHz radar)
    │
    │ serial frames @ 256000 baud
    ▼
USB-UART adapter (FTDI / CH340)
    │
    │ /dev/ttyUSB0 or COM3
    ▼
presence-sensor.py  (or the desktop app, with its session instead of a token)
    ├──► POST {presence, distance, device_id} with Bearer token → /api/presence
    │       └─► Tiedenwerk webapp stores the latest state in memory
    │             └─► the kiosk polls the state while the sensor is enabled
    │
    └──► On no-presence > DISPLAY_OFF_DELAY:
            SendMessage(SC_MONITORPOWER, 2)   (Windows: turn display off)
            Or wlopm/xset on Linux

Reading the dashboard

Open Settings → Screensaver → Presence on the kiosk to check its live status. Wave at the sensor; the displayed state updates on the next poll. Presence state resets when the webapp restarts and returns when the sensor posts again.

Configuring sensitivity (optional)

The LD2410's default sensitivity is good enough for most living-room scenarios. If you need to tune it:

  • B-variant has a Bluetooth config app on Android — pair to the sensor and adjust per-zone sensitivity / max range
  • All variants accept config commands over the serial port; the aio-ld2410 library exposes them. See its docs for the API.

Common adjustments:

  • Max distance: default 6m, drop to 3-4m for a kitchen-counter mount to avoid triggering on people in the next room
  • Static / moving target threshold: default works; raise if you get false positives from a HVAC vent

Why radar, not PIR?

PIR (passive infrared) sensors detect movement, not presence. If you stand still while reading a recipe, a PIR thinks you've left and turns the screen off. The LD2410's mmWave radar detects a stationary human chest moving (breathing) at sub-millimeter resolution, so "still but present" stays "present."

Logging

The script writes to C:\presence-sensor.log (Windows) or wherever you configure — the watchdog messages there tell you exactly when the sensor last delivered data. There's no log rotation — the file just grows. Clear-Content it manually if it gets large.

Troubleshooting

Symptom Likely cause
No serial port found USB-UART driver missing. Check Device Manager (Windows) or dmesg (Linux) for the device. FTDI drivers are usually built-in; CH340 needs a download from wch.cn.
API returns 401 TIEDENWERK_PRESENCE_TOKEN (or the old KINBOARD_PRESENCE_TOKEN) on the kiosk does not match PRESENCE_SENSOR_TOKEN in webapp/docker/.env. Recreate the webapp after changing the Docker value.
API returns 503 PRESENCE_SENSOR_TOKEN is empty in the running webapp. Run setup again or set it manually, then recreate the webapp.
"Permission denied" on /dev/ttyUSB0 User not in the dialout group: sudo usermod -aG dialout $USER, then re-login.
Detected presence but display doesn't turn off The Windows SC_MONITORPOWER message doesn't always work — depends on monitor + driver. As a fallback, force-blank via PowerShell: (Add-Type ... SendMessage(...)).
Distance reads 0 always Sensor wired to TX/RX swap incorrectly. Try swapping the wires.
Watchdog reconnects every 30 s Serial cable is loose, or the sensor is power-cycling (check the 5V supply) — or the baud rate is wrong (LD2410 default is 256000, not 115200; check BAUD_RATE in the script).
Display turns off mid-conversation DISPLAY_OFF_DELAY too short. Bump from 30 to 90 s.

Related

Clone this wiki locally