dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
485 stars 116 forks source link

Sensors divided over source files #110

Open rikki78 opened 1 year ago

rikki78 commented 1 year ago

Hi, First of all thanks for your great library. This is really useful for integrating remote sensors into Home Assistant. In my case I have made one sketch that can be configured to use different sensors. So based on a config file for example temperature sensors or binary switches are defined which all use the same code. To make it readable I have spread the code over different files, where the temperature sensor HASensorNumber is in a different file as the devices HADevice and HAMqtt. This gives issues as the order of initialisation of the global objects is not under my control, so I figured I need to create the sensors dynamically (like you suggested in this issue https://github.com/dawidchyrzynski/arduino-home-assistant/issues/103). I haven't tested this but I guess it will work. The question I'm having now, is how to create multiple sensors dynamically? For examples if there are more binary switches. Can you suggest how to do this? thanks