This is not a clock

Monday, November 12th, 2018 at 8:01 pm

Do you see this thing that looks a lot like a bedside clock? While it may be displaying the current time, it is not really a clock…

To explain what I mean I need to go back a few weeks to when I was inspired to finally do something with the various electronic components I have collected over the years (five years since I plugged in a DS1820 sensor) for home automation. After some tinkering and relying heavily on the examples that come with the libraries I had this going:

On this breadboard is a D1 mini microcontroller, a DHT22 temperature and humidity sensor, and a 4-Digit 7-Segment Display from Adafruit. It is fantastic that other people have done the hard work of sorting out the libraries for the board (with wifi), the sensor and the display. Everything I have done with these is based on the examples provided.

What is happening in this photo is that it is alternating between displaying the temperature and the humidity, but over the following few weeks I continued to tinker until I had it publishing the temperature (and humidity) over wifi to an MQTT server in order to get the data into Home Assistant which displayed this:

Yes there are two data sources, because I had five (more on the way!) of these microcontrollers and they are cheap and simple enough to scatter around the house. They are easy to run from a USB charger, so anywhere I have a powerpoint I can have a device. I now have a lot more configured in Home Assistant and I am feeding in data from other sources, but they will be posts of their own, for I need to get back to explaining why this is not a clock.

Apart from adjusting to the time change, my biggest annoyance with daylight saving is the clocks that need to be manually changed. It is a lot easier these days as phones/computers/etc will automatically update, but I still have a few clocks that need to be adjusted.

My bedside clock is one of these and while I know you can buy a clock that adjusts automatically, when I last looked (it has been a while) I didn’t like the look of them and they were too expensive. So this was going to be my first project and at first I was going to make it a clock that would use time protocols to get the correct time, but you still needed to deal with timezones and other things.

So why not make it dumb? I have a linux box that is always on (where I am running services such as Home Assistant) and it has already dealt with the timezone and DST changes. Every minute it could publish what it thought was the current local time, something as simple as cron running a bash script:

#!/bin/sh
DATE=`date +%H:%M`
mosquitto_pub -h localhost -t home/localtime -m $DATE

The requirements for the “not a clock” are pretty simple:

  • Connect to wifi and the MQTT server, subscribe to the home/localtime topic
  • Every 60 seconds publish temperature/humidity to MQTT (for Home Assistant to collect)
  • Whenever a message arrives on the home/localtime topic, output to the LED display

Making enclosures is probably what I will have the hardest time with (do I buy a 3d printer?) and until this evening I had bare electronics hanging from the wall in four locations around my house. With the need to be able to see the LED display I had the idea of using a clock radio as the enclosure. I decided against gutting my working clock radio so over the weekend I stopped by the local Kmart where I found a clock radio for the lofty price of $15:

(I’m showing the silver model as the picture gives a better idea of what it is, the black model is just a black obelisk, it also comes in rose pink if that suits your colour scheme)

It is not designed to be opened up so some force was required, but after removing the internals and the strategic application of tape and hot glue I have what is in the top picture. I have the temperature sensor taped to the side because I think it wouldn’t get the best reading being inside the case, limited airflow and some heat from the electronics could skew the reading.

An unexpected bonus of this specific radio (and it makes sense from an electrical certification point of view) is that it runs from 5 volts and comes with a small power supply. I retained the socket for this and wired it up to the D1 mini instead of using a USB power adapter. I also kept the board for the buttons on the top of the clock, in the future it might be nice to use them to as a trigger for some action…

I have a lot more to say about Home Assistant, including how I am testing out control of my central heating (just in time for summer…) using a D1 mini equiped with a relay. I have also realised that the remaining clock I have to manually adjust for daylight saving is my stereo, the 25 cd stacker double tape desk stereo that I use as my alarm to play the radio… is there a wifi speaker in my future?

Tagged with:

2 Responses to “This is not a clock”

  1. Great write-up of your time-displaying, temperature/humidity-sensing IoT device. I will investigate the D1 Mini when I get time.

    John Kaye - November 14th, 2018 at 8:27 am

  2. Don’t just look at the D1 mini, there are other ESP8266 based devices out there. Also consider devices based around the ESP32 which is newer, but also more expensive.

    Stephen - November 14th, 2018 at 9:32 am