Paucities

How I learned to stop worrying and love Shelly

June 20, 2021 | by Radoslav Paučo

shelly1

Recently, We automated heating in our house. The idea was to substitute ordinary thermostat, that takes into account only the temperature in the room you are heating, with something smarter, something aware of different temperatures all around. A smart thermostat that takes into account temperature in the heated room, outside temperature, as well as temperature of building’s structure. Be cool and save energy. Hardware-wise the original solution was based on Node-MCU Lua v3 (ESP8266 chip) board. The board is cheap, under 10 euros, has WiFi connectivity, but was also a great pain in the ass for me.

I flashed board with MicroPython, connected temperature sensors (DS18B20), wired it together, wrote my program in python, uploaded it to the board and… everything went well. In laboratory conditions. But only there. I soon realized that I must rewrite my program. It was constantly getting stuck few minutes after reboot of the board. Usually running out of memory. I had to sacrifice nice OOP-style code structure for structure that was saving memory. Although the board has generous 4MB storage, it has only about 100 KB of operational memory out of which less than 40 KB were left for my program after booting.

Apart from the low operational memory, lack of logging and monitoring and troublesome connectivity were issues as well. I know that there are solutions using this board used for even more complicated calculations, communicating with external services smoothly, but making it run properly required so much effort. Switching to cloud computing, logging and monitoring options would be so much better and easier to setup there. And previous project based on the cloud was such success. So, I ported whole solution to the cloud and I got rid of the Node-MCU board and bought Shelly 1 smart relay.

TL;DR: the code controlling relay – switching on/off the boiler – runs as AWS Lambda function in the cloud. Temperatures are provided by Luftdaten service, measured by our own PM/meteorological device, and by Shelly 1 itself through temperature shield directly connected to two DS18B20 temperature sensors. Finally, the actuation of the switch is via Shelly cloud service.

The controlling code runs periodically every minute. From AWS perspective we are connecting Amazon Event Bridge event’s rule to AWS Lambda function. The temperature of the boiler water and temperature of the building’s structure are measured by Shelly 1 itself through temperature addon. Shelly device streams the temperatures as well as it’s state automatically to its own cloud service from where you can access it through REST API call or MQTT.

We also deployed another AWS Lambda function which is running every 15 minutes and queries Luftdaten service for current outside temperature data. The temperature is then stored in AWS Systems Manager’s parameter store where it is available for the controlling code. The controlling code turns on/off the Shelly 1 relay through REST API call on Shelly’s cloud service’s dedicated endpoint. Neat.

Yeah, and logging and monitoring? You have AWS Lambda’s logging and monitoring at hand, no additional special setup needed. Logs are accessible through AWS Cloud Watch connected to your AWS Lambda function. And right in the AWS Lambda web GUI you have visual monitoring feature where you can monitor invocations, failures, response times, etc. of your function and drill down to individual logs at a given time if needed.

Monitoring feature in AWS Lambda GUI.

After so much struggle with Node-MCU board, this Shelly + AWS setup is just godsend. You can find code here.

Few words about wiring. Again, Shelly made it so easy. We just cut the male-female ordinary electric cord in the middle and wired it to Shelly as in the picture below. To be precise, We didn’t cut the ground wire, just the other two. We used cage clamps, aka wago clamps, hence no soldering was required. This way We basically created a smart plug which is also able to measure temperatures. Here you can find a video on how to connect the temperature addon and temperature sensors to Shelly 1 or Shelly PM relays. You just group same-colored wires into the same clamp.

I didn’t mention a word about how to get from input temperatures to water temperature setpoint value. Currently, let’s say it’s mostly heuristics related to our house. You can check the code here. I plan dedicated post about this. One last detail, the turn-off signal can still come from the ordinary room thermostat. Moreover, this turn off signal is in the hierarchy above the Shelly control so we don’t need to worry about overheating the house.

It’s 30+ °C outside right now so the whole heating shebang was put to it’s summer sleep. Writing about the winter projects cools me down. You know because they’re so cool.

Leave a Reply

RELATED POSTS

View all

view all
Translate »