RETAIN is an essential feature of any MQTT implementation. Without RETAIN, device information can get lost when a service like Home Assistant who uses MQTT subscription to get device info, has an issue. For instance, when Core sends out an MQTT discovery message (essential for Home Assistant auto-discovery) the RETAIN flag ensures that the device is still available after Home Assistant reboots.
Best posts made by marcvl
-
[MQTT-Core] Support for RETAIN
-
RE: Newbie question - how to get started?
Github repository of my MQTT Thermostat running on Core2 is here.
It's pretty cool. The thermostat supports various modes: off/auto/manual/heat/cool/fan. You can specify minimum cycle duration as well as set swing mode parameters. It automatically gets discovered by Home Assistant. You can set thermostat mode and target temperature in Home Assistant and they will automatically get reflected on the Core2 display.
It currently relies on the ENVII module for temperature reading, and requires a WIFI connection and an active MQTT broker. I haven't had time to implement error handling, so if something goes wrong, it might be non-obvious to figure out why. More work to be done.
I couldn't figure out how to enable touch for a specific screen area without using visible buttons with M5stack_UI, so instead I used an lvgl button with invisible borders.
-
Randomness ...
So I decided to use UIFlow/Core2 to build a Nest-like smart thermostat. The thermostat communicates with the outside world (Home Assistant, AC Relay, Heater Relay, Fan Relay, etc.) through MQTT. All of the HVAC functionality (setting target temperature, deciding to turn on/off heat/AC, handling cycle times, swing mode, etc.) are built into my code.
You can download my code from github: https://github.com/marcvl64/M5Stack-Core2-Thermostat and also check out a screenshot of what the UI looks like.
The code is missing certain pieces (MQTT comms with HA's HVAC platform is missing), but by and far, all features mentioned above are done.
As I started adding more features, I increasingly started noticing random behavior when uploading my code to the Core2. Specifically:
-
Background color changes make certain display elements disappear. They might come back after a screen refresh (20 sec) or they might not. It's random.
-
The buttons at the bottom of the screen don't work reliably. After upload, 1 might work, sometimes 2, and if I'm lucky all 3 will work. Again random.
-
Sometimes everything just freezes for no apparent reason.
-
Sometimes when I add a completely innocent line of code (display debug info), I see odd behavior after uploading (e.g. certain screen elements that used to show up no longer show).
I have 3 questions:
1/ Am I trying to do too much with UIFlow? Have I outgrown the resources of the Core2? How would I know? How can I monitor what is going on?
2/ If yes, what would be the better development environment? Arduino?
3/ If no, what am I doing wrong? -
-
RE: Randomness ...
Github link is here. It includes the .m5f file and the images that go above the buttons A, B, and C. I was trying to copy and paste the Python to make it easier to read, but copy/paste doesn't seem to work on my MAC version of the UIFlow software :-(
-
RE: Newbie question - how to get started?
This is all super helpful. Thank you! I will start building up my UIFlow-generated micro python code step by step to see when I hit the error that causes the reboot.
-
RE: [MQTT-Core] Support for RETAIN
Hi: Is there an update to this request? It seems to me that this would be very easy fix ... just adding the 'retain flag' parameter to mqtt messages. This is a very essential feature for mqtt auto-discovery with remote clients (such as Home Assistant). Without retain, Home Assistant loses all the configuration details about the M5Stack device after every HA reboot. The M5stack becomes 'unavailable' to HA and it's only after rebooting M5Stack that the device becomes available again.
-
RE: Newbie question - how to get started?
Made great progress. Thermostat is up and running. Display is rendering fine. MQTT integration with HA works...
One question as I'm working on aligning all the labels, sliders, images and other visual elements .... I can't figure out how to "center align" things. For example, I have a text label with varying length. I'd like to anchor that label on the screen by specifying the x,y coordinates of the center of the label, as opposed to the top left corner. How do I do that?
-
RE: Newbie question - how to get started?
@ajb2k3 Yes, this is in micropython. I need to do a little bit more work but will post my code on Github soon.