I originally thought I’d need to adjust the hole in the garbage can model to move it upward, but actually the key was putting the microcontroller into the bin with the port facing down.
It does need to be very slightly wider than it currently is, but on my test piece I did that a file and it’s looking good!
I was worried that only having two LEDs instead of four would result in it not being bright enough, but I’m running it at half brightness with my example code and it seems great.
Next steps are to find a way to fit the tiny microcontroller I’m going to use into the bottom so the USB port lines up for power, and of course print the bin in white.
Itās been a little while since I posted about my smart home journey because Iāve been pretty busy of late with other things (like my actual job), but rest assured that there has been progress ā albeit slow.
As I mentioned before, Iāll be adding three microcontrollers to our smart home setup in various parts of the house. Each project is going to go through three stages: proof of
concept, prototype, and final product.
Today is our first proof of concept, and itās going to test whether or not I can hook our existing doorbell up to WiFi.
Getting a notification when someone rings the doorbell was the first thing Flo asked for when I mentioned I was going to start making our home smarter, and I quickly set
about figuring out how to do it: happy wife, happy life.
Some initial ideas (adding a relay to the doorbell circuit) were fairly quickly dismissed, and so I came up with a piece of out of the box thinking that Iām actually very proud of.
Iāll be using magnetic switches, also known as reed switches, elsewhere in the house. In fact, we already have them on many of the doors and windows as part of our burglar alarm, and you may well have some in your house too. They work by opening and closing when a magnet is brought into proximity with the switch. My flash of inspiration came when I was thinking about how a doorbell works: an electromagnet pulls a hammer into one chime when the doorbell is pushed, and then a spring pushes it into a second chime when the button is released and the electromagnet turns off. So, if I put a reed switch next to the electromagnet then the switch will flip when the magnet
turns on. Genius!
Happily for me, our doorbell has two chimes: one in the main floor hallway, and one in the basement. I wouldnāt want to run cables up the wall to the chime on our main floor, but the basement one is the mechanical room so the aesthetic is really not a consideration.
Using a switch as an input for the NodeMCU is simple. Really the only thing to think about is that the digital input pins are āfloating,ā which means that if nothing is connected then the result you get from them is unpredictable. To account for this you use either a āpull upā resistor between the input pin and the 3.3v pin, or a āpull downā resistor between the input pin and the ground pin. I went for a pull down resistor between the input pin and ground, then put the switch between the input pin and 3.3v.
For the proof of concept I wrote some simple code to display the input pin state over the serial console, taped the reed switch place and, despite some protest from the dog, rang the doorbell a few times.
If youāve been keeping up with my #SmartHomeĀ series (and if you havenāt, why not?) youāll already know that I have plans to make more of my home āsmartā using Home
Assistant as the software that ties everything together, and some DIY NodeMCU-based hardware that Iām going to build myself as a learning opportunity.
Another important piece of the puzzle, but one that I havenāt previously mentioned, is MQTT.
MQTT is āa publish-subscribe-based lightweight messaging protocol for use on top of the TCP/IP protocol,ā at least according the slightly suspect grammar of the person that wrote the Wikipedia article about it.
I learned about MQTT at the same time I learned about Home Assistant, although I didnāt initially appreciate its power. Iāve been using it from the start to enable Home Assistant to know where we are: our phones run an app called OwnTracks which publishes
location data to an MQTT ābrokerā (server). Home Assistant subscribes to these updates, which means it immediately knows about it when our location changes.
I love this whole solution, not least because itās very easy to run my own MQTT broker (Iām running MosquittoĀ in a Docker container on my home server) and Iām therefore entirely in control of our location data ā itās not being shared with the developer of some app or service I have no insight into.
This publish/subscribe model and the lightweight nature of MQTT makes it perfect for āInternet of Thingsā (IoT) devices to communicate with each other, and when you add Home Assistant into the mix it gives me all the tools I need for any sensors I build
to feed their data into my smart home ecosystem, and for my smart home controller to feed commands to any devices.
Indeed, Iāve already built my first little NodeMCU app that leverages the technology.
Iāve ordered almost all the components I need for my upcoming hardware projects from China, and theyāre only just starting to arrive. Happily the NodeMCUs themselves were amongst the first shipments to land on my doorstep, so even though the only thing I can really do with them right now is programmatically turn their internal LED on and off, I have still been able to use this to start learning: Iāve made it an internet controlled
LED.
As promised, Iām going to be sharing both the hardware and the software as I take this DIY Smart Home journey. There is no DIY hardware here, just the NodeMCU itself, but Iāve published both the Arduino sketch and Home Assistant configuration Iāve used for the video.
Granted, all itās doing here is running the example āBlinkā program that comes with the Arduino IDE, but the important point is that the little light is turning on and off because I uploaded some code that tells it to.
Itās not connected to a computer here. The USB cable is simply plugged into a power outlet.
Granted, all itās doing here is running the example āBlinkā program that comes with the Arduino IDE, but the important point is that the little light is turning on and off because I uploaded some code that tells it to.
Itās not connected to a computer here. The USB cable is simply plugged into a power outlet.
Ever since I bought my own home nearly a year ago, Iāve
become increasingly interested in making it smart.
Right off the bat, I feel like I should clarify what that
means to me. The ability to turn some lights on or off with an app is not
smart, in my opinion ā the smart way of controlling lights is by flicking a
switch conveniently located in the room you wish to illuminate.
A smart home needs to be much more intelligent. Itās about
automation. Itās about the home being able to notify me if something is
happening that I need to know about. Itās about being able to accomplish things
with minimal difficulty, not adding complexity and more steps.
Thatās where off the shelf āsmart homeā solutions really
started to fall down for me. I could spend hundreds or maybe even thousands of
dollars, for what? The ability to turn on my living room lights while Iām still
at the office? Why would I ever need to do that?
Nevertheless, the lack (in my opinion) of a pre-packaged,
useful, holistic solution that accomplished my vision of what a āsmart homeā
should be didnāt deter me from tackling things bit by bit. It started with our
burglar alarm. It has internet connectivity which sends me alerts in the event
that something unexpected is happening, and lets me arm or disarm the system
from my phone ā which I actually do find useful.
Next up was our thermostat. The one that was installed when
we bought the house was an old-fashioned one with a simple mercury switch
inside. You set the temperature, and that was it. We replaced that about a
month ago with something programmable (it doesnāt need to be as warm in here at
night as it does during the day; it doesnāt need to be as warm if nobodyās
home), and I took the opportunity to get one with WiFi so I can set the
temperature remotely. Thatās not useful in and of itself, but if you take that
functionality and look at it in the context of my wider vision then the
thermostat is certainly something Iād like to be able to programmatically
control.
It was around this same time that I discovered home assistant, and now my dream is
starting to come alive.
Home Assistant is an open-source project that runs on a
variety of hardware (I was originally running it on a Raspberry Pi, and Iāve
since switched to running it in a Docker
container on our home
server). It has a ton of plugins
(ācomponentsā) that enable it to support a variety of products ā including our
existing alarm, thermostat, streaming media players, and others (including,
somewhat ironically, the colour-changing lightbulbs we have in our family
room). It includes the ability to create scripts and automations, it uses our
cellphones to know our locations, and can send us push notifications.
My initial setup was all about notifications. If we both
leave the house but the burglar alarm isnāt set then it tells us (and provides
an easy way to fix the issue). If we leave one of the exterior doors open for
more than five minutes, it notifies us (or just one of us, if the other is
out). I also created a dashboard (that you may have seen in my last post) to display some of this stuff on a monitor in my office.
Since installing the thermostat Iāve added more automation.
The time we go to bed isnāt always predictable, but when we do go to bed we set
the alarm. So, if itās after 7pm and the alarm goes from disarmed to armed, the
thermostat gets put into night mode. If nobody is home then the temperature
gets gradually turned down based on how far away we are.
If nobody is home at dusk then it turns on some lights and
streams talk radio through the family room speakers to give the impression that
someone is.
This stuff meets my definition of smart, and Iām barely
scratching the surface. The open nature of the platform not only means that Iām
not tied to a particular vendor or technology, but also means that I can add on
to the system in a DIY way.
Which is exactly what Iām going to do. Iāve bought some NodeMCU microcontrollers which are
WiFi enabled, Arduino IDE-compatible
development boards designed to the basis for DIY electronics projects.
Watch this space, because over the coming months Iāll be
connecting our doorbell, garage door and laundry appliances to Home Assistant.
Iāll be learning as I go, and Iāll share the hardware and software.