2.1 KiB
sensors
Purpose
Ingests events from physical sensors (Zigbee door/window contacts, motion PIRs, leak sensors, GPIO-attached hardware) and republishes them onto the internal Vigilar bus in a normalized form. Maintains the current sensor state in SQLite so the web UI and rule engine always know whether a contact is open/closed, a leak is active, etc.
Key files
vigilar/sensors/bridge.py—SensorBridge: subscribes tozigbee2mqtt/#, normalizes payloads vianormalize_zigbee_payload, republishes tovigilar/sensor/{id}/{event_type}vigilar/sensors/gpio_handler.py— direct GPIO input handling; publishes the samevigilar/sensor/{id}/{event_type}topicsvigilar/sensors/registry.py— loads configured sensors, maps Zigbee friendly names to sensor IDsvigilar/sensors/models.py—SensorEventdataclass and protocol enumvigilar/sensors/__init__.py
MQTT topics
Subscribes: {zigbee2mqtt.mqtt_topic_prefix}/# (external Zigbee2MQTT broker, usually zigbee2mqtt/#)
Publishes:
vigilar/sensor/{id}/{event_type}— normalized sensor events (contact_open, contact_closed, motion, leak, etc.)
Database tables
sensors— static sensor registry (read bySensorRegistry)sensor_states— current-state table, kept up to date viaupsert_sensor_state
Depends on
- External Zigbee2MQTT broker (same Mosquitto instance,
zigbee2mqtt/...topic prefix configurable via[zigbee2mqtt]TOML section) storage— usesvigilar.storage.queries.upsert_sensor_state
Consumed by
events— classifiesvigilar/sensor/#messages intoCONTACT_OPEN,CONTACT_CLOSED,MOTION_START, etc. and persists them to theeventstableweb— thesensorsblueprint readssensors/sensor_statesfor the dashboard
Notes
SensorBridge deliberately skips zigbee2mqtt/bridge/... status messages and ignores unknown friendly names with a debug log. Both the Zigbee bridge and the GPIO handler produce identical vigilar/sensor/{id}/{event_type} topics so the rest of the system cannot tell a Zigbee door contact from a GPIO-wired one — that's intentional.