Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4741

General • Pico W -> RFM69 + MQTT + Home Assistant = Automatic Awning Control

$
0
0
Friends, I just completed my first Pico-W project. This was a bunch of fun and I'm really glad I tried out this hobby!

Background

I have an awning in the back that we mostly open during the summer to keep the sun from coming in the back windows. I suspect it saves a fair bit of energy in the heat of the summer, but we aren't home to open it five days a week. Plus there's all that inefficient button pressing. Much more efficient to spend (checks watch) like 30-50 hours and hundreds of dollars learning about microcontrollers and buying tools to work with them.

Apparatus

The physical design of this project is a Pico W, an RFM69HCW breakout board, a cheapo spring antenna from Amazon, and a 3d-printed enclosure. The Pico W connects to an MQTT server on my network and announces itself as an awning using the HomeAssistant MQTT protocol. HomeAssistant can send commands, which the Pico-W will relay to the SomfyRemote library. This library in turn actuates the radio's data pin, sending an OOK message at 433.42MHz that is understood by the awning itself.

For someone with more experience, I'm sure that this project doesn't have much challenge to offer, but besides the general background of fun challenging oneself, here are the specific bits I thought were interesting.

The Somfy protocol (the protocol for my awning) requires a 16 bit rolling code, which I store in the top two sectors of flash. I didn't want to have to erase a whole sector every time the code updates. Fortunately, it simply increments each time you send a command to the awning. To store this increment in a minimum of flash erases, I simply count the number of zero bits in the last two sectors. Each time a command is sent, I zero one more bit. When the counter rolls over, I erase the whole range and start again from zero.

I found writing an RFM69 SPI driver to be diverting. I did the minimum required to get OOK working. If I were going to spend more effort on it, I'd probably want to do the work on the version that supports LoRA.

I did not find the prospect of copying the SomfyRemote library to be much fun. So I wrote enough of an Arduino core to get the existing arduino library working, and not an ounce more.

Learning CMake and FreeRTOS was fun. FreeRTOS was aggressively unnecessary for this project, but I'm happy I learned it so I can just use it as a default for future efforts. Well worth it to pay 100kHz per second to get all the synchronization primitives it offers, especially since my projects now take advantage of the second core by default with zero incremental effort. I put the bits that I think I can reuse on my next project in two separate repositories: http://github.com/jaguilar/freertos_default_config and https://github.com/jaguilar/jagspico. Some of the stuff in there -- maybe all of it really -- is pretty rough. I ain't proud.

Designing the enclosure was massively diverting. I want to do more projects with 3d-printed parts. Looking for any excuse to buy a printer really. My biggest mistake was not factoring in the size of the risers for the button pins. There is not enough space in the enclosure to hook them up, so they are not operable in the "release" version of the project. Ah well. We still have the remote that came with the awning.

I did design my own PCB for this, but it did not work. It was also bigger than the proto board I ended up with cause I'm a goose.

Materials
Links

Photos and videos: https://photos.app.goo.gl/QfiYWZvH5Hk56P1fA

Source code: https://github.com/jaguilar/awning/tree/main/src

Statistics: Posted by jags84 — Wed Jun 05, 2024 3:51 am



Viewing all articles
Browse latest Browse all 4741

Trending Articles