Hey, all. I have posted a few times as I have been learning about the M5stack and how to integrate it with ESPHome and Home Assistant. Many thanks to all who have assisted me along the way. Your feedback and guidance has been invaluable.
My goal has been to use my M5stack as a remote control around my house, and last night, I finished coding this. But, my code is suboptimal as there is much repeated code. I would rather use arrays, and I am sure there are other ways of improving this code that I don’t know about yet.
So, I submit it here for feedback. All constructive feedback appreciated.
I have done some searches here on the forums, and I see from other posts that arrays are supported – I just need to learn how to do that, then implement it. Any other suggestions on how to improve this code?
I wrote a blog post last night describing what the code does. In summary, it displays 3 different types of data (weather forecast, sensor data, and switch status), and the data type is selected by pressing button C on the M5stack. Button A cycles between individual entities on a page (e.g., forecast for today, tomorrow, next day; or temp/humidity sensor A or sensor B; or light A, light B, light C). In forecast or temp/humidity sensor view, button B toggles between “all” and “one.” In light view, button B toggles the indicated light on and off. (There is a bug where it toggles a light on/off even in “all lights” view. I will fix this soon.)
In particular, I would like to define a multi-dimensional array of screen types that also specifys the data to show on each page (e.g., the friendly name of a sensor/light as well as the Home Assistant entity name). Right now, all of that is hard-coded – and, while it works, I don’t like it. There has to be a better way.
I should mention that I don’t know C++ at all. I remember C from 30 years ago, but I never coded C++ before. All C++ code contained in my code is copied from forum posts here.
Direct link to my code: https://github.com/ataridude/ESPHome/blob/f1939cdb52467f6cdd97f825106ca5b95655232b/m5stack_home_control.yml
Thanks for any constructive feedback.