Hello. I’m trying to implement the MQTT Sensor: Get temperature and humidity example on my ESP8266 but with the useful MQTT-discovery. I tried different approaches, searched the forum and am currently at an dead end. [See EDIT below: SOLVED]
Initially I tried to submit the following array-type config-payload to “homeassistant/sensor/sensorRoom/config”:
[{
“device_class”: “sensor”,
“name”: “Temperature”,
“state_topic”: “homeassistant/sensor/sensorRoom/state”,
“unit_of_measurement”: “°C”,
“value_template”: “{{ value_json.temperature | float/100}}”
},
{
“device_class”: “sensor”,
“name”: “Humidity”,
“state_topic”: “homeassistant/sensor/sensorRoom/state”,
“unit_of_measurement”: “%”,
“value_template”: “{{ value_json.humidity | float/100}}”
}]
This payload does not add anything and produces an error in the log:
Traceback (most recent call last):
File “/usr/lib/python3.6/asyncio/tasks.py”, line 179, in _step
result = coro.send(None)
File “/usr/lib/python3.6/site-packages/homeassistant/components/mqtt/discovery.py”, line 60, in async_device_message_received
payload = dict(payload)
ValueError: dictionary update sequence element #0 has length 5; 2 is required
Submitting the two sub-payloads subsequently to “homeassistant/sensor/sensorRoom/config” results in no error, but only the “temperature” reading shows up in HA. According to the logs the second config-payload is a duplicate:
2017-10-03 04:41:03 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/sensor/sensorRoom/config: {“device_class”:“sensor”,“name”:“Temperature”,“state_topic”:“homeassistant/sensor/sensorRoom/state”,“unit_of_measurement”:“°C”,“value_template”:“{{ value_json.temperature | float/100}}”}
2017-10-03 04:41:03 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor sensorRoom
…
2017-10-03 04:41:03 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/sensor/sensorRoom/config: {“device_class”:“sensor”,“name”:“Humidity”,“state_topic”:“homeassistant/sensor/sensorRoom/state”,“unit_of_measurement”:“%”,“value_template”:“{{ value_json.humidity | float/100}}”}
2017-10-03 04:41:03 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor sensorRoom
So am I right to say that HA identifies duplicates of MQTT-discovery by the object_id given in the config topic and that the above example cannot be reproduced with MQTT-discovery because it has identical entity_ids for both sensors? Or am I doing a big mistake? Thanks.
EDIT
After reading my post once more I found my obvious mistake. I need 2 different configuration topics to have 2 different object_ids:
“homeassistant/sensor/sensorRoomT/config”
“homeassistant/sensor/sensorRoomH/config”
Should this thread be deleted or kept for archive purposes?