Thermostat becomes a roller shutter UI

Open source software and hardware is often hard. Contrary to proprietary and closed solutions like Apple’s, open / free alternatives are often not polished. They usually take you lots of work to make them usable.

However, they give you all the power. You can do anything you want with them… Like turning a thermostat into a roller shutter user interface.

When I was thinking about automating my roller shutters, I didn’t know how to start. Luckily, I found a post from Recretonica where it was explained how to build a DIY roller shutter controller from scratch. I reproduced it easily with a Wemos D1 mini, a 6 channel relay and a HLK-PM01 AC to 5V transformer. No more electronics were needed.

Electronics: Wemos D1 Mini, 6 channel relay and HLK-PM01

An Arduino sketch controls the roller shutters position using MQTT. It subscribes to the corresponding MQTT topics, and commands the relay for the seconds that the roller shutter expends to move to the new position. You can find the sketch in my roller shutter repository.

I also designed a 3D printed case for the electronics, so they got isolated inside the roller shutter box, away from any humidity bough by the shutter.

Roller shutter controller case box

This was my first 3D design, so it was not easy. I was happy to start learning Blender. But the reality is that there is some distance from what you design, how it gets printed, and how it works. I had to make some tests and prototypes, and still, I had to cut back and adapt the final print. You can find the 3D case in my Thingiverse account.

Case box with electronics and top

Finally, I was wondering how to arrange the switch for 3 roller shutters at once. I envisioned the thermostat as the perfect place to control the roller shutters: it is placed in the same room, it is tactile, so you can control the positions with one gesture. So I modified the my thermostat‘s software so we could control the 3 roller shutters in their own screen, at once. You can find the modifications in the roller-shutter branch of my fork of hestia-touch-one-ui repository.

Hestia Pi’s roller shuter UI

Watch this video to see how well it works!

Hestia Pi controlling roller shutters

Open Bedroom Thermometer: Integration with the thermostat

My main goal of setting an extra thermometer in the bedroom was to integrate it with my open thermostat, placed in the living room. My house is not big, but when we go to bed, we are not in the living room anymore. We want it to watch for the temperature in our bedroom.

Of course, I wanted to automatize this switch as well. Every night, when we go to sleep, the thermostat switches the tracking of the temperatures from the living room thermometer, to the bedroom thermometer. When we wake up, it switches back to the living room thermometer, the one in the thermostat.

One of the great things about using open hardware and software is that you can customize everything. I could change and adapt both the UI and the logic of the thermostat to incorporate the new temperature readings

UI integration

HestiaPi UI is just Javascript (Vue.js) and HTML, running on Kweb, a very light browser for Raspberry Pi. I redesigned the interface to accommodate the new figures. I also added the buttons to switch manually the thermometer that drives the thermostat behavior, from the thermostat sensor to the bedroom thermometer and back. HestiaPi UI communicates over MQTT, the same way than ANAVI Thermometer, so it was pretty straightforward to copy the same logic.

You can find the code in the anavi-thermometer branch of my fork of hestia-touch-one-ui.

Modified interface of HestiaPi including ANAVI Thermometer readings

Backend integration

HestiaPi logic is built on top on OpenHAB. Despite OpenHAB is a bit heavy for running in a Raspberry Pi Zero, it provides HestiaPi with all the power of smart home capabilities.

Backend integration involves new OpenHAB things, channels, items and rules, so it deserves its own post: ANAVI Thermometer – HestiaPi integration

ANAVI Thermometer things and channels in Hestia Pi’s OpenHAB

I feel grateful for having found these two great open projects and being able to play with them, learn many things and having a feeling of accomplishment after customizing my own setup!

This is the last post on these ANAVI Thermometer series, but not the last from Hestia Pi… More hacking to come!

ANAVI Thermometer – HestiaPi integration

This integration works with HestiaPi Touch ONE v1.2

These changes need the HestiaPi Touch UI to be updated with my anavi-thermometer branch.

Add-ons

ANAVI Thermometer publishes values in JSON. They are easy parsed in OpenHAB with the JSONPath transformation add-on. We will need to install it first

Things and items

ANAVI Thermometer

We create a separate Generic MQTT Thing for setting the channels related to ANAVI Thermometer values

Generic MQTT Thing configuration

Then we create appropriate channels for ANAVI Thermometer’s temperature and humidity. They will probably be pushed to workgroup/<your id>/air/temperature and workgroup/<your id>/air/humidity MQTT paths. We use JSONPath for extracting actual values.

ANAVI Thermometer temperature channel
ANAVI Thermometer humidity channel
ANAVI Thermometer thing with channels

Finally, we need to link channels to their corresponding items. You can create them from the link channel, clicking at the arrows on the right

ANAVI Thermometer temperature item
ANAVI Thermometer humidity item

Thermometer Switch

We create an extra MQTT thing, Thermometer Switch, that will be used for selecting which temperature the thermostat is following; based on this thing, HestiaPi will act on changes of the temperature sensor from HestiaPi or the one from ANAVI Thermometer

Thermometer Switch thing

We need to create a new channel for this new thing. We will be reading its state from hestia/local/stat/thermometerswitch MQTT topic

Thermometer Switch channel

And finally, we create an item for this channel

Thermometer Switch channel with its linked item

Hestia Local Sensor Readings

A side effect of the Process Sensor Changes rule modification below is that the original MQTT channels used by HestiaPi to publish local sensor readings hestia/local/temperature and hestia/local/humidity will now publish ANAVI’s readings when Thermometer Switch has Anavi value. We will need to add two extra MQTT things and items to keep those local sensor readings. Former channels become current values the thermostat is considering for taking the decisions about turning on or off.

We add LocalTemp and LocalHumi MQTT channels pointing to hestia/local/localtemperature and hestia/local/localhumidity

LocalTemp channel
LocalHumi channel

And we link these things to their corresponding items LocalTemp and LocalHumi

LocalTemp item
LocalHumi items

Rules

Initialization rule

We will need to add the initial value for Thermometer Switch, that will default to HestiaPi’s value My. This value is not very descriptive, but will match HestiaPi’s item names and will make things easier in the rules below.

initState("ThermometerSwitch", "My");

Process Sensor Changes rule

Process Sensor Changes is the rule that updates temperature, humidity and pressure proxies. It also decides whether to update temperature based on hysteresis changes.

We add two new triggers so the rule is ran also whether AnaviTemp or AnaviHumi change

AnaviTemp trigger for Process Sensor Changes rule
AnaviHumi trigger for Process Sensor Changes rule

However, we need an extra condition: we set the constraint that the sensor that changed has to match the value of ThermometerSwitch, that is, only update values from HestiaPi’s sensor when My is selected in ThermometerSwitch, and only update values from ANAVI’s sensors when Anavi is selected

event.itemName.indexOf(items["ThermometerSwitch"]) == 0 || event.itemName == "MyPressure"

Finally, we slightly modify the rule to get the value from the relevant sensor, that can have My or Anavi prefix now

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/hestia/utils.js');
load(OPENHAB_CONF + '/automation/lib/hestia/defaults.js');

var device;
var logName = "sensor";

logDebug(logName, "Changed "+event.itemName);

if (event.itemName == 'MyPressure') {
  device = 'Pressure'
} else {
  device = event.itemName.replace(items["ThermometerSwitch"], "");
}

// Update the proxy
events.sendCommand("My"+device+"Proxy", newState);

// Verifying the newState can be parsed is already checked in the but only if…
var newReading = parseFloat(newState.toString());

var prev = items["Previous"+device+"Reading"].floatValue();
if(prev == NaN) prev = 0;

var hyst = (device == "Temp") ? DEFAULTS.get("Temp"+items["TempUnit"]+"_DIFF") : DEFAULTS.get(device+"_DIFF");

logDebug(logName, "Processing " + device + " with value " + newState + " and prevState " + prev + " and delta " + delta);

var delta = Math.abs(newReading - prev);
if(delta > hyst) {
  logDebug(logName, "Updating Previous"+device+"Reading with " + newState);
  events.postUpdate("Previous"+device+"Reading", newState);
}
else {
  logDebug(logName, "Ignoring " + device + " sensor reading, change is too small");
}
Modified Process Sensor Changes rule

Process Local Sensor Changes rule

Finally, we add an extra rule to publish HestiaPi’s sensor values to the extra MQTT things LocalTemp and LocalHumi that we created before

They will be triggered when MyTemp or MyHumi change

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/hestia/utils.js');
load(OPENHAB_CONF + '/automation/lib/hestia/defaults.js');

var logName = "localsensor";

logDebug(logName, "Changed "+event.itemName);

var device = event.itemName.replace("My", "");

// Update the proxy
events.sendCommand("Local"+device, newState);

Open Bedroom Thermometer: Light detection and screen fade

One of my main concerns about placing a new display in the bedroom was light contamination. The same rule applies both to clean interfaces and when going to sleep: no distractions. Luckily, handling the screen brightness of my ANAVI Thermometer was easier and more straightforward than I imagined

The first step was getting a light detector, so we can discern when the room goes dark. I just noticed the BH1750 light sensor is recommended in ANAVI’s web. And, as I mentioned about my surprise on the availability of cheap components, I could find it easily and very cheap.

BH1750 light sensor

Plugging it into my ANAVI Thermometer couldn’t be more straightforward. Leon’s firmware is prepared to detect it and include the readings both in the OLED display and in its own MQTT topic.

Adding it to the thermometer case was surprisingly easy as well. The case I 3D printed already had a slot in one side that I could file down a bit. The light detector bulb just made a perfect fit!

And finally, there was the job of adapting ANAVI Thermometer’s firmware to program the display fade according to the light detected in the room. Arduino’s libraries like U8g2 already come with a setContrast API call to reduce the screen light. But it is not enough. Luckily, there is a thread on Arduino’s forum on how you can also play with the OLED display precharge registry to reduce the brightness even more. I had to do some calibration work, trying several values with both the smaller and the right-size OLED displays. Behavior with different values might vary a lot, but I found a setup where I can do a decent fade out depending on the values measured by the light detector.

Finally, using the U8g2 setPowerSave call, I turn off the display when there is no light.

You can find all these changes to in my screen-fade branch of ANAVI’s Thermometer firmware.

And this way we get a quiet environment for sleeping!

ANAVI Thermometer’s screen fades with the room light

Open Bedroom Thermometer: Aesthetic Customization

I am pretty happy with my University education. I studied Telecommunications Engineering in Spain, which is a mix of Computer Science, Electrical Engineering and Telecommunication Systems. I think it gave me a solid base for a broad range of topics, from the signals inside a circuit to software engineering principles.

However, something I have missed is some basic formation on UX and design. I think it would have helped me a lot in many of my projects. Along the years, I have valued the importance of these aspects in a project: you might have the most wonderful technical implementation of something but, I you can’t let your users understand it, you will fail.

Suitable case

The first part obvious for placing my ANAVI Thermometer in the bedroom is that it needed a case. Dust protection, protection from humans, aesthetics. ANAVI’s setup is quite convenient for development, but not as suitable for a product that is going the take part of the decoration of your bedroom.

Vented Box – Anavi Thermometer in Thingiverse

Luckily, one of the Crowdsupply field reports on ANAVI Thermometer included a printing model for a case. I hadn’t a 3D printer yet, so I ordered it to be printed using one of the apps plugged into Thingiverse, and I got a mail package with my case ready to be placed. Cool!

Matching display

A white on black OLED display was more suited for this set than the yellow and blue that came from Anavi Technology. However, when the new display arrived, I discovered it had different dimensions. It didn’t fit in the 3D printed case.

OLED display

I didn’t want to order a new copy of the case. So I did an endless search for a display with the same dimensions than ANAVI’s. It was hard to find one. Finally, I found this 0.96 inch display from AZDelivery that was a perfect fit

Display reshape

I apply UX and design principles in my work, not only in product development, but also in the interfaces or the user experience of a command tool. I think the hardest but more beautiful job is making the complexity simple. I praise Apple for this. Despite I would never buy one of their products, I can admit the value and experience they used to deliver in each of them.

There were obvious things to cut in the original display information. Leon has done a great job creating a software that works for a lot of purposes (as we will see in the next article on the light sensor). But I am not plugging a water temperature sensor, so the Air word is not needed. The temperature unit as well, we just use Celsius. And also Humidity word, the % sign is just enough

These cuts allows increasing the font size and placing the figures in one row. I also prefer a sans-serif font, which I chose from the amazing U8g2 library.

ANAVI’s default display vs customized display

I have published all the changes in display customization. You can find them in the display-reshape branch of my fork of ANAVI Thermometer firmware.

Open Bedroom Thermometer

Open Bedroom Thermometer

After setting up the mighty open source and open hardware Hestia PI in the living room, an extra thermometer in the bedroom was the next step. Hestia PI‘s does its job amazingly well during the day. But when the night comes, we don’t care about the temperature in the living room, but in the bedroom. We have only one central heating, the bedroom temperature is the one that should drive during the night.

In the spirit of my requirements, I found an amazing project that filled my expectations: ANAVI Thermometer.

Leon Anavi is a open hardware enthusiast from Bulgaria that creates awesome open hardware and open software projects. His products are open hardware certified. He has infrared transmitters, gas detectors, fume extractors… And, of course, a thermometer.

ANAVI Thermometer
ANAVI Thermometer with its original kit. Source: Anavi Tecnology

I purchased one from Crowdsupply. But I didn’t just placed it. I wanted to make some customizations to fulfill my needs and make it look more like an end user product! So I made the following changes:

The final result in its placement looks great!

My thermostat, with root access

HestiaPi looks awesome. An open software and open hardware project, Raspberry Pi based, customizable LCD touch screen, it is all you can ask as a basis for your home IoT infrastructure.

It took some time to arrive though. I ordered it via Crowd Supply, a great site with wonderful open hardware gadgets and solid ethic principles. I made my order in mid October, but due to some problems I was not going to get it until March. Luckily, I didn’t have any problem cancelling my order and I could ask it directly from Greece to Spain. Why crossing the Atlantic ocean there and back again when it had just to cross the Mediterranean sea?

Adapting it to my heater was a bit challenging. My heater offers 2 wires, while HestiaPi expects only one. It just sends the power line back to the heater.

There is a hack to remove the power transform and use a 5V USB charger to decouple the line from the heater and the power line from the raspberry.

Another option I was considering was to cutting the track that connects the power line with the heater. But I didn’t want to damage my brand new thermostat!

Decouple power line from heater line in HestiaPi

Finally, I ended up disassembling the heater. I found out it has just a fuse before the line sent to the thermostat.

Connections in front of the heater board
Connections in back of the heater board

In fact, in the installation manual there is a option to connect a thermostat with an anticipatory resistor that matched my idea. I finally went for this last option, so I didn’t have to break the HestiaPi and soldering the power line.

I am very happy with the result. It works great!

HestiaPi installed and working

But I am more excited with what will come next. I am overwhelmed by the possibilities. Besides the capabilities of OpenHAB, the touch screen is built in HTML and Javascript, so I will totally customize it to meet my needs!

I am already integrating another open software hardware, the ANAVI Thermometer.

And integrating the roller shutters into the thermostat will come next!

Teaching the computer to talk

One of the first cool things you want to do with your kitchen computer is teaching it to talk. The visits come and you ask it to play music or open the roller shutters. Cool!

But current solutions come with a cost. Some people don’t care if their conversations are sent to servers at the other part of the world.

I want it full privacy preserving. Of course we have nothing to hide, but privacy is not about having nothing to hide

So this has to be full free and open source software.

There are some alternatives for FOSS voice assistants. I went for Mycroft, as it is well integrated with openHAB. It is a great working solution, backing FOSS up. They have recently even open sourced their server backend.

Setting Mycroft

Mycroft core repository is very well documented. It has a getting started script that does all the stuff for you: installing required Debian packages, setting the Python virtual environment… it even git-pulls to get the last commits from the repository. In a few minutes you have a Mycroft instance up and running without further problems.

There is still tweaks needed for two things: running without using the Mycroft home and using your own speech2text service.

Running without Mycroft Home

Mycroft Home seems to be a nice service, but I don’t need all the goodies they offer. I just want a local configuration without any data sent to a remote server.

There are some options to setup your own backend, including Mycroft’s own backend or a simpler personal backend.

But you can even use Mycroft without home. Just blacklisting some skills (mycroft-pairing.mycroftai, mycroft-configuration.mycroftai), it prevents Mycroft for connecting to the home. Setting these options in the configuration file is just enough.

DeepSpeech: Run your own speech2text service

Mycroft is a great tool for listening to the microphone, waiting for the wake word and running a big set of skills: from saying hello to reading a Wikipedia entry. However, it still needs a speech2text service that recognizes your words.

There are a few options for speech2text, including, of course, using Google STT. But we exactly want an alternative to it.

Fortunately, people at Mycroft are collaborating with DeepSpeech, a nice project from the Mozilla Foundation based on Tensorflow. At Common Voice they are gathering the required data for training the model, and it is surprisingly easy how you can start contributing from minute one.

Setting DeepSpeech in Mycroft is quite straight forward using the DeepSpeech Server python package. You can easily set its own python environment, writing a configuration file and it will start listening to Mycroft’s wave audios in a local port.

Finally, you just configure Mycroft to use DeepSpeech

And here you are! Your full open source local server voice assistant working in your kitchen!

Mycroft core running in debug mode

Next steps

In Spanish, please. Our mother tongue is Spanish, so we expect using home automation in that language. While there is a overwhelming set of resources in English, including DeepSpeech models, Spanish resources are not that ready to go. There are however posts about using transfer learning or even a published DeepSpeech Spanish model, so training our own model shouldn’t be very hard.

Changing the wake word. Hey Mycroft is not bad, but it would be awesome if you could use your own name. Mycroft people make it very easy, their Mycroft Precise repository provides us with a ready-to-train recurrent neural network and a pretty straightforward training your own wake word howto

Screensaver dashboard. Our touch screen speakers disconnect when the screen switches to sleep mode. This prevents us from listening to Mycroft responses. Besides, there is lag from when you touch the screen and it wakes up. I am fixing this writing a simple Gnome Extension that impedes the screen going to sleep at certain times or in certain conditions. It also will show the time, the weather, and icons with some shortcuts to most used programs.

More coming soon!

More than a huge tablet in the kitchen

One of the first ideas I wanted to fulfill was having a huge tablet in the kitchen

I envisioned several usages:

  • Playing music while cooking
  • Managing the shopping list, synchronized with our mobile phones
  • Watching tv / netflix / youtube videos
  • Showing a clock / weather / other statuses when idle

I started looking for a huge tablet. Samsung Galaxy View was a very promising option. With its 18.4″ it made the grade. However, it seemed to be a little old, it was released some years ago, and Samsung Galaxy View 2 was not available yet. I was also looking in Ali Express but couldn’t find anything convincing.

So I changed my mind and considered another option: PC + touch screen

We have just resized a cupboard in the kitchen to make room for a highest fridge. So it was the perfect site for a PC, just close to the screen place. I knew I could remove the back side of the furniture to let the PC cool down. My only concern was about kitchen smoke and the ventilation of the fridge.

The advantage this option that I could use my beloved Debian instead of an Android distribution and make the “tablet” a full customizable server. It enabled some other possibilities and usages, like installing openHAB or any other voice controlled automation software

I investigated GNOME support for touch screens and it seemed to be pretty decent, with multitouch gestures support and touch keyboard

So then, the challenge was to find a touch screen that worked with Debian.

As expected, touch screen vendors don’t officially support Linux, but a very few exceptions. There was a promising Acer T232HL but there was reported to have a buggy Via USB 3.0 hub that prevented for working well in Linux and needed and extra USB hub to fix it.

The people at Tech Global have a video demonstrating Ubuntu working with one of their monitors. I wrote them to ask for an estimation of the cost. They were very kind, but the price was out of my scope.

Finally, I found Planar monitors were working well in Linux and even they claim to support Linux in their web. I chose this Planar Helium PCT2485 of 24″. Bigger than the Samsung Galaxy View tablet!

Besides, I bough this MSI Cube 3 Silent as PC box. Without fans, it was to be as silent as a all day turned on computer has to be. But still, more powerful than a Raspsberry Pi. With enough storage to make small experiments, like training a speech to text model.

These are some pictures of the final setup:

GNOME working on touch screen!
A cupboard can be a nice place for a server
The Planar touch screen besides the PC on top of the fridge

After 2 months of usage, I have to say I am very happy with the result. We are using it a lot for playing music, managing our shopping notes. GNOME does a good job with the touch screen. And I have already implemented some features using openHAB. More coming!

Booting…

This is the first post of a series on home automation and Internet of Things (IoT)

IoT is a topic that never caught by attention. I have seen a lot of hype about how it would become the next great thing. But I never saw it exploding, not in the same way Internet or the Web did.

However, after I became a house owner, I started to envision the possibilities of playing with my own house. I didn’t have the limits of renting anymore. I could do whatever I want, like cutting a cupboard in a half to make room for a higher fridge… and place a computer inside it.

Besides, I discovered an entire new world of devices at very affordable prices with a blooming open community. My head explodes when I think in all the possibilities and new cool things. Despite the time constraints of a full time job and raising a child.

In this series I will write my last advances on home automation. I will try to use open hardware and free open source software while I can.

I started buying our open source thermostat. Because if you don’t have root access to your thermostat, someone else does

I do have root access to my thermostat