Is it possible to discover multiple sensors with a single discovery topic?
I have sensors that publish on sensor/<id>
with the payload:
{"Sequence": 32570,"Watt": 685.20,"kWh": 2475.654,"battery": 100,"FreqErr": 0.28,"Sensor":<id>}
The following discovery message works for a single sensor but would it be possible to discover all sensors with one discovery message?
{
"device": { "name": "Sensor 123", "identifiers": "123", "model": "Sense", "manufacturer": "Acme Inc."},
"unit_of_measurement": "kWh",
"json_attributes": ["Sequence", "FreqErr", "battery"],
"name": "Sensor123 kWh",
"unique_id": "sensor_123_kwh",
"state_topic": "sensor/123",
"value_template": "{{ value_json.kWh | round(2) }}"
}
What i want is to auto generate 123
based on what is published on sensor/
.
Edit:
I’ve come so far that I’ve created the following automation, but I don’t know a reasonable condition to stop spamming the mqtt.
- id: 'MQTT_auto'
alias: Sensor auto-conf
trigger:
- platform: mqtt
topic: sensor/+
condition: []
action:
- data_template:
payload: >
{"device": {"sw_version": "215a4aa", "name": "Sensor",
"identifiers": "{trigger.payload_json.Sensor}}",
"model": "Sense", "manufacturer": "Acme Inc."},
"unit_of_measurement": "kWh",
"json_attributes": ["Sequence", "FreqErr", "battery"],
"name": "Sensor {{ trigger.payload_json.Sensor }} kWh",
"unique_id": "sensor_{{trigger.payload_json.Sensor}}_kwh",
"state_topic": "sensor/{{trigger.payload_json.Sensor}}",
"value_template": "{{'{{ value_json.kWh }}'}}"}
topic: home/sensor/sense/{{ trigger.payload_json.Sensor }}/config
service: mqtt.publish