dont read unconfigured sensors
This commit is contained in:
@@ -359,6 +359,15 @@ friendly names shown by Zigbee2MQTT:
|
|||||||
nano config.yaml
|
nano config.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Sensor entries whose `name` begins with `CHANGE_ME` are placeholders and are
|
||||||
|
excluded from MQTT polling, RRD creation, graphs, and the HTML dashboard. Rename
|
||||||
|
an entry when its physical sensor is ready. The marker is configurable:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
collection:
|
||||||
|
excluded_name_prefix: CHANGE_ME
|
||||||
|
```
|
||||||
|
|
||||||
By default, the databases are written to `/var/lib/rrd` and the generated
|
By default, the databases are written to `/var/lib/rrd` and the generated
|
||||||
graphs to `/var/www/html/sensors`. Create those directories and grant the user
|
graphs to `/var/www/html/sensors`. Create those directories and grant the user
|
||||||
running the collector ownership:
|
running the collector ownership:
|
||||||
|
|||||||
+7
-6
@@ -7,6 +7,7 @@ mqtt:
|
|||||||
collection:
|
collection:
|
||||||
interval_seconds: 600
|
interval_seconds: 600
|
||||||
mqtt_timeout_seconds: 15
|
mqtt_timeout_seconds: 15
|
||||||
|
excluded_name_prefix: CHANGE_ME
|
||||||
|
|
||||||
storage:
|
storage:
|
||||||
data_directory: /var/lib/rrd
|
data_directory: /var/lib/rrd
|
||||||
@@ -19,15 +20,15 @@ logging:
|
|||||||
sensors:
|
sensors:
|
||||||
- name: Server room
|
- name: Server room
|
||||||
topic: zigbee2mqtt/sensor_server_room
|
topic: zigbee2mqtt/sensor_server_room
|
||||||
- name: Sensor 2
|
- name: CHANGE_ME Sensor 2
|
||||||
topic: zigbee2mqtt/CHANGE_ME_SENSOR_2
|
topic: zigbee2mqtt/sensor_supply_room
|
||||||
- name: Sensor 3
|
- name: CHANGE_ME Sensor 3
|
||||||
topic: zigbee2mqtt/CHANGE_ME_SENSOR_3
|
topic: zigbee2mqtt/CHANGE_ME_SENSOR_3
|
||||||
- name: Sensor 4
|
- name: CHANGE_ME Sensor 4
|
||||||
topic: zigbee2mqtt/CHANGE_ME_SENSOR_4
|
topic: zigbee2mqtt/CHANGE_ME_SENSOR_4
|
||||||
- name: Sensor 5
|
- name: CHANGE_ME Sensor 5
|
||||||
topic: zigbee2mqtt/CHANGE_ME_SENSOR_5
|
topic: zigbee2mqtt/CHANGE_ME_SENSOR_5
|
||||||
- name: Sensor 6
|
- name: CHANGE_ME Sensor 6
|
||||||
topic: zigbee2mqtt/CHANGE_ME_SENSOR_6
|
topic: zigbee2mqtt/CHANGE_ME_SENSOR_6
|
||||||
|
|
||||||
rrd:
|
rrd:
|
||||||
|
|||||||
+9
-1
@@ -77,6 +77,8 @@ def load_config(path: Path) -> Config:
|
|||||||
if not isinstance(configured_sensors, list) or not configured_sensors:
|
if not isinstance(configured_sensors, list) or not configured_sensors:
|
||||||
raise SystemExit("The configuration requires a non-empty sensors list")
|
raise SystemExit("The configuration requires a non-empty sensors list")
|
||||||
|
|
||||||
|
collection = raw.get("collection", {})
|
||||||
|
excluded_prefix = str(collection.get("excluded_name_prefix", "CHANGE_ME"))
|
||||||
sensors: list[Sensor] = []
|
sensors: list[Sensor] = []
|
||||||
slugs: set[str] = set()
|
slugs: set[str] = set()
|
||||||
topics: set[str] = set()
|
topics: set[str] = set()
|
||||||
@@ -88,6 +90,8 @@ def load_config(path: Path) -> Config:
|
|||||||
raise SystemExit("Every sensor requires a name and topic") from error
|
raise SystemExit("Every sensor requires a name and topic") from error
|
||||||
if not name or not topic:
|
if not name or not topic:
|
||||||
raise SystemExit("Sensor names and topics cannot be empty")
|
raise SystemExit("Sensor names and topics cannot be empty")
|
||||||
|
if excluded_prefix and name.casefold().startswith(excluded_prefix.casefold()):
|
||||||
|
continue
|
||||||
slug = safe_slug(name)
|
slug = safe_slug(name)
|
||||||
if slug in slugs or topic in topics:
|
if slug in slugs or topic in topics:
|
||||||
raise SystemExit(f"Duplicate sensor slug or topic: {name!r}, {topic!r}")
|
raise SystemExit(f"Duplicate sensor slug or topic: {name!r}, {topic!r}")
|
||||||
@@ -95,7 +99,11 @@ def load_config(path: Path) -> Config:
|
|||||||
topics.add(topic)
|
topics.add(topic)
|
||||||
sensors.append(Sensor(name, topic, slug))
|
sensors.append(Sensor(name, topic, slug))
|
||||||
|
|
||||||
collection = raw.get("collection", {})
|
if not sensors:
|
||||||
|
raise SystemExit(
|
||||||
|
f"No active sensors remain after excluding names beginning with {excluded_prefix!r}"
|
||||||
|
)
|
||||||
|
|
||||||
storage = raw.get("storage", {})
|
storage = raw.get("storage", {})
|
||||||
logging_config = raw.get("logging", {})
|
logging_config = raw.get("logging", {})
|
||||||
interval = int(collection.get("interval_seconds", 600))
|
interval = int(collection.get("interval_seconds", 600))
|
||||||
|
|||||||
Reference in New Issue
Block a user