MQTT Temp sensor, address or logical name, in OH or on source 8266 device


I’me sure there are a few people who have multiple sensors on one device (onewire) and use MQTT.

I’m interested if there is a std so to speak on where to logically label sensors;

  1. Logically label sensors on 8266 in MQTT to something meaningful, i.e. attic, lounge etc; or
  2. Let 8266 send sensor address as part of MQTT, and assign a logical label to it in OH.

First option requires recoding 8266 with new sensor additions, or when sensor is replaced.

Second option I should be able to just add a new sensor or replace, new devices would appear in MQTT with new address, then make adjustments in OH to marry new address to logical name.

Each has pro and cons.

I have a d1 mini that uses a temperature sensor and a reed switch.

They’re both on a sensors called garage-sensor which publishes a temperature topic and and reed/state

So in entirety is looks like

Plus a free more topics as they use homie so online status WiFi, network, MAC address etc.

In order to achieve, that your ESP code would have to be changed significantly.
You would have to scan the I2C bus regularly to capture active addresses,
Then use those addresses to retrieve data from each sensor. Note the each sensor may have a different library for it in addition on the I2C library. SO you can’t just plug in an I2C sensor and expect it to just works and start reporting values…

You can’t add ALL the possible libraries in your code and predict ALL the sensors you will attach

Conclusion, stick to Option 1 and set-up OTA updates on your ESPs to make your life easier.

Thanks, local via OTA is a great idea.

I prefer to make the sensor itself do as much of the work as it is capable of doing for me. So, for example, I have a NodeMCU in the masterbedroom so I use the topics sensors/mbr/temp, sensors/mbr/humidity, etc. I’ve only one sensor in a given room but if I were to add another I would probably add a sensor ID between the sensor reading and the room name in the Topic.

If I were to replace the sensor I’d have to log into it to configure it anyway so modifying the topic it publishes to is just one more of the fields I need to edit, and I can do it all in one place, i.e. on the sensor, instead of needing to set up the NodeMCU and then change openHAB.

I am a strong advocate of using names for things that are meaningful for the human and that goes for MQTT topics as well. So I like my topics to be self descriptive and meaningful to me. I can give just about anyone those topics above and they can know without any other context that the MBR temperature gets published to the sensors/mbr/temp topic.

But honestly, I don’t think the difference between the two approaches is enough to have a strong opinion one way or the other.

1 Like

I like the principal of getting as much done on the device as possible.

When combined with OTA this a good solution.