Smart Thermal & Solar Controller Pico W (2)(RP2350)

A Modular, Fault-Tolerant Project to Cherry-Pick!

Good Morning All,

I wanted to share a project I’ve been refining.

On the surface, it’s a full-scale hydronic and solar thermal controller.

But under the hood, it’s really just a Raspberry Pi Pico W 2 (RP2350) running MicroPython, built from a bunch of simple, independent blocks.

I designed it so that the logic, hardware control, and UI are totally decoupled. More importantly, I built it to survive the real world—handling API crashes, sensor failures, and power outages without locking up. Whether you’re a beginner looking for a simple API script, or a veteran wanting to see an AI-audited state machine, grab whatever pieces you find useful!

Things You Could Scavenge From This Project or the whole thing!

The “Elimination Round” Logic, Instead of a nightmare of nested if/else statements, the logic engine, after testing ten methods!, uses a simple Finite State Machine (FSM) that knocks out dangerous or expensive options before picking the best heating strategy.

Fault-Tolerance & Recovery, the system checks a localized error_log.txt on boot to detect if it crashed previously. It features a hardware Watchdog Timer (WDT) that is actively fed even during long, 30-second API retries to prevent looping resets. If a temperature sensor fails (reads -999.0), it isolates the error, logs it, and falls back to safe defaults. Finally, if the main loop hits a fatal exception, a hardware try/except block forces the relays into a safe “Idle/Solar” state.

The Grid-Price Dodger, a clean MicroPython script that hits the Amber Electric API to fetch real-time grid prices.

The Serial-to-Desktop Bridge, for this I built a PC companion app using Python and Tkinter. It listens to the Pico via USB serial and draws live rolling telemetry charts using Matplotlib.

The Telegram AI Bot, the PC app hooks into Telegram so I can control the system from my phone, and it even uses the Gemini AI API to audit the daily CSV logs to make sure the Pico didn’t break any safety rules.

An example of the code.

— 2. THE ELIMINATION ROUND —

Start with every possible hardware state configuration

candidates = list(STATE_MAP.keys())
trace =

If it’s nighttime, instantly eliminate any state that turns on the AC relay

if time_phase in [“NIGHT”, “MORNING”]:
candidates = [c for c in candidates if STATE_MAP[c][8] == 0]
trace.append(“BlockCurfew”)

If the grid price is spiking, eliminate states using high-draw auxiliary heaters or AC

if pcc >= SPIKE:
candidates = [c for c in candidates if STATE_MAP[c][8] == 0 and STATE_MAP[c][4] == 0]
trace.append(“BlockSpike”)

If the roof isn’t hot enough, knock out any state trying to pump solar

if not solar_permitted:
candidates = [c for c in candidates if not (STATE_MAP[c][0] == 1 and STATE_MAP[c][3] == 1)]
trace.append(“SunCold”)

If anyone is interested I am happy to provide details of any module/part/all of the project.

As I have mentioned somewhere else on this forum, I am a retired experienced engineer, my career covered a wide range of areas, true coding was not one of them, ideas and design yes, software development yes, a little 4gl stuff with MS Access, mechanical and servos yes, thats it. This project was a hard won enjoyable “battle” with Gemini Pro, managed AI makes things possible that you may have only dreamed of.

Excuse typos or format, typing is not my thing.

Having fun.

best regards
keith

2 Likes

Hi Keith,

This is a seriously nice bit of integration. I really like the way you’ve broken it into independent chunks so a sensor fault, API hiccup, or reboot doesn’t take the whole system down with it.

That “elimination round” approach is a great pattern too — much easier to reason about than a giant decision tree, especially once you need to prove safe behaviour around edge cases. The watchdog handling during long retries and the boot-time crash detection are also the kind of practical details that make the difference between a demo and something that can live in the real world.

The telemetry bridge and AI log audit are a clever touch as well. It gives you both live visibility and a second layer of sanity-checking without burdening the Pico with extra non-mission-critical tasks.

Would be keen to see under the hood if you are willing to share!
Liam

HI Liam

Thanks for the response; I’m pleasantly surprised by the details you derived from the post.
As the project result was better than I expected I considered asking Core if they had any interest in a detailed post on the project, but really did not know who to ask. As you see from the bridge I have used the project+Ai to explore many of the ideas I often have on any software or system I have worked on.
The usb mimic is a bit of an idiosyncracy, I know I could have done all sorts of web based stuff but to be honest the last time I tried that was in the 90s, I like simple, and that mimic is that.
For info the pico does not care if the pc exists or not, it lives alone unless someone talks to it.
The bridge or if the bridge is alive the telegram bot.

If you would like to see the whole thing, personal use only, drop me a note by phone or email.

rgds

keith