Category Archives: electronics

Build a wireless MQTT temperature and humidity sensor for your Home Assistant

Over the last months, I became more and more addicted to Home Assistant (Hass.io) and MQTT low cost wireless sensors. I was already familiar with several home and industrial automation systems that all come with a certain hardware (and price) and build upon a completely proprietary software stack. So long story short, I was searching for a good community-backed open source home automation system that is easy to set up and runs on my old Raspberry.

As home automation seems to be a broad area of interest I thought there should be hundreds of open source community projects out there. I was not as easy as I thought and there are not so many home automation projects out there. It seems as if the market is broadly dominated by large vendors that offer integrated solutions.

After some cumbersome fails I was finally able to find a real gem in the home automation area, which is called the Home Assistant, or short Hass.io. Home Assistant comes as a lightweight installation that perfectly fulfills following requirements:

  1. Its lightweight, low resource consuming
  2. Easy to set up
  3. Nice web interface, that also comes pretty well with my tablet and smartphone (no app required, responsive web UI is great on your mobile device too) See a live demo here.
  4. Lots of community components available (>1000), such as Alexa, IFTTT, Hue, Sonos, Cromecast, Webcam, and many more.
  5. Fully configurable through plaintext YAML files
  6. It comes with an integrated MQTT broker!
  7. Supports automation scripts, such as turn light on at sunset
  8. Best of all its written in Python and its open source

The first step towards building my own MQTT wireless weather station was to set up a Home Assistant instance on my old Linux laptop. If you already got Python3 running on your system, the set up process is pretty straight forward, just type:

python3 -m pip install homeassistant

After successful installation you just enter the .homeassistant configuration folder and adapt the .yaml configurations that control what your Home Assistant instance is showing and how elements are organized in Web UI.

The most important configuration files are configuration.yaml that contains the core configuration about sensors and components and groups.yaml that groups all your components into visual tabs within the UI. Within my installation i chose to use a default group, one for my living room and one for controlling my pool, as i is shown in the screenshot below:

As my screenshot already shows, my Home Assistant instance already contains some MQTT based sensors for continuously informing me about the temperature and humidity (outside, and in living room). You can put the sensor output into any of your configured tabs. The same sensor info can also be present in multiple tabs at the same time.

To add a new MQTT sensor into your core configuration file, simply add following sensor section into your core configuration.yaml file:

sensor:
  - platform: mqtt
    name: "Temperature"
    state_topic: "/home/outdoor/sensor1"
    value_template: "{{ value_json.temperature }}"
    unit_of_measurement: '°C'
  - platform: mqtt
    name: "Humidity"
    state_topic: "/home/outdoor/sensor1"
    value_template: "{{ value_json.humidity }}"
    unit_of_measurement: '%'

You can then show this newly added sensor value in any of your configured groups, as shown below:

default_view:
  name: Home
  view: yes
  entities:
    - sensor.airquality
    - sensor.temperature
    - sensor.humidity
    - sensor.yr_symbol
    - sun.sun
    - camera.mjpeg_camera
    - device_tracker.alice
    - device_tracker.bob
    - switch.robby
    - switch.lamp
indoor:
  name: Livingroom
  view: yes
  entities:
    - sensor.temperaturelivingroom
    - sensor.humiditylivingroom
    - media_player.livingroom
pool:
  name: Pool
  view: yes
  entities:
    - sensor.watertemperature
    - switch.poolcover
    - switch.poollight
    - switch.poolpump
    - switch.poolbot

Now its time to test if the sensor would show a value in case it receives an MQTT value through the configured MQTT topic. Therefore, Home Assistant offers a simple MQTT test message UI in which you can simulate any incoming MQTT message, as shown below. Just enter your MQTT topic and send a static value:

After a click on the ‘publish’ button those two values 30 and 70 will appear in your sensors for temperature and humidity. You can do that try-run for all of your MQTT bound sensors, which is a convenient feature for testing the server side functionality of your home automation.

Next step is to build a cheap temperature and humidity sensor that sends its measurements over WLAN to your Home Assistant MQTT broker. As base sensor board I decided to use an Esp32 microcontroller board that offers a cheap (~5 USD platform) with integrated WLAN stack and many digital and analog input pins. See below an image of the chosen Esp32 board:

The Esp32 board can easily be flashed over a USB cable and it runs with a standard Arduino bootloader. You can use your Arduino Studio to program your tiny Esp32 board. To measure the temperature and humidity, the combined digital DHT22 sensor was used, as shown below:

To connect the DHT22 sensor to your Esp32 board simply attach the Vin pin to the 3V pin of the Esp32 board, the Ground to any of the Ground pins and the signal pin to any of the Esp32 digital input pins.

Following Arduino code snippet shows how to initialize the DHT22 sensor and how to read and report the sensor value through a MQTT message:

#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <DHT.h>
#include <DHT_U.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>

/* Globals used for business logic only */
#define MQTT_VERSION MQTT_VERSION_3_1_1
// MQTT: ID, server IP, port, username and password
const PROGMEM char* MQTT_CLIENT_ID = "sensor2_dht22_s";
const PROGMEM uint16_t MQTT_SERVER_PORT = 1883;
// MQTT: topic
const PROGMEM char* MQTT_SENSOR_TOPIC = "/home/house/sensor1";
// sleeping time
const PROGMEM uint16_t SLEEPING_TIME_IN_SECONDS = 60; // 10 minutes x 60 seconds
// DHT - D1/GPIO5
#define DHTPIN 5

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
WiFiClient wifiClient;
PubSubClient client(wifiClient);

/* Business logic */
// function called to publish the temperature and the humidity
void publishData(float p_temperature, float p_humidity, float p_airquality) {
    // create a JSON object
    StaticJsonBuffer<200> jsonBuffer;
    JsonObject& root = jsonBuffer.createObject();
    // INFO: the data must be converted into a string; a problem occurs when using floats...
    root["temperature"] = (String)p_temperature;
    root["humidity"] = (String)p_humidity;
    root["airquality"] = (String)p_airquality;
    root.prettyPrintTo(Serial);
    Serial.println("");
    /*
    {
    "temperature": "23.20" ,
    "humidity": "43.70"
    }
   */
    char data[200];
    root.printTo(data, root.measureLength() + 1);
    client.publish(MQTT_SENSOR_TOPIC, data, true);
    yield();
}

setup() {
    dht.begin();
    Serial.print("INFO: Connecting to ");
    WiFi.mode(WIFI_STA);
    WiFi.begin(cconfig.ssid, cconfig.pwd);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.println("INFO: WiFi connected");
    Serial.println("INFO: IP address: ");
    Serial.println(WiFi.localIP());
    // init the MQTT connection
    client.setServer(cconfig.mqtt, MQTT_SERVER_PORT);
}

 

void loop() {
    dht.begin();

    if (WiFi.status() != WL_CONNECTED) {
        WiFi.mode(WIFI_STA);
        WiFi.begin(cconfig.ssid, cconfig.pwd);
         
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        // Read temperature as Celsius (the default)
        float t = dht.readTemperature();
         
        if (isnan(h) ||isnan(t)) {
            Serial.println("ERROR: Failed to read from DHT sensor!");
        }
        else {
            publishData(t, h, aq);
        }
        delay(5000);
    }
}

Download the full source code at Github.

After connecting, flashing and running our tiny 15 USD wireless sensor we will continuously receive updates of actual temperature and humidity measurements. Those measurements are shown within your Home Assistant views. A very nice feature of Home Assistant is also that it stores historic measurements and that you can get a chart of past trends by a single click into the UI, as shown below:

Overall, Home Assistant is the perfect open source platform for your own home automation projects, no matter if you run it on your old laptop or on a tiny Raspberry Pi. It offers all the flexibility in terms of attaching any kind of MQTT sensor or message provider and is a great platform for playing around with your electronics hardware and it has a cool Web UI too!

Meet Ozobot my kids best robot friend

On my last trip to San Francisco this year I visited the California Academy of Sciences where i was immediately fascinated by a tiny robot called Ozobot. Ozobot looks amazingly cute and is able to perform a lot of magic that ultimately teaches your kids how to program by using a visual programming language thats similar to MIT Scratch. Ozobot moves along a black line and reacts on color codes that tell the bot to either turn, move faster or slower or to change the color of its led. Even if your kids are not programming so far its fun to paint mazes where the little friend moves around. Ozobot’s primary sensor is the color scanner that allows the bot to follow the black line and to read color codes in order to control its movements. Another amazing feature I found our recently is the possibility to program the little robots movements by using a visual block language called Ozobot Bit Blockly. Simply program your own Ozobot program online and transfer the program visually onto your bot without any cable involved. Its super cool to see how the bot receives its new program by just sending color codes to its scanner. Ozobot is clearly one of the most innovative teaching robots available right now, because its super simple to use and it looks so cute.

Ozobot kids learning to program

Ozobot Bit blockly

VNC Server for Siemens Simatic HMI Panels

MobileVNC offers a tiny footprint VNC server software solution for the different Siemens Simatic HMI touch panels. No matter if you operate a large fleet of Simatic HMI KTP400 Comfort Touch Panels that run on a ARM CPU processor or a Simatic HMI TP700 on x86 (486) Intel CPU, MobileVNC will offer good native performance. Since its first publication more than 10 years ago the professional MobileVNC VNC server solution offers a simple and cost effective way for remote controlling and maintaining industrial PCs, thin clients or even Windows powered mobile devices.

ARM CPU powered Siemens Simatic HMI KTP400

 Simatic HMI TP700 on x86 CPUs

Simatic HMI TP700 on x86 CPUs

Submit your Arduino Projects to the Maker Fair in ROME


Maker Faire Rome - The European Edition
Save the date for the European Maker Faire that takes place from 3 to 6 October in ROME, Italy!

Massimo Banzi, one of the inventors of Arduino, is promoting and hosting this cool Make Event in October. It will be the perfect event for meeting the community of DIY activists and Makers all over Europe. The deadline for submitting your own Make projects and creations has been postopened until end of June. Submit your own Arduino projects here.
Maker Faire showcases the amazing work of all kinds and ages of makers—anyone who is embracing the do-it-yourself (or do-it-together) spirit and wants to share their accomplishments with an appreciative audience.
Topics for the Maker Call are: 3D Printing, Robot, Education, Design, Fashion, Arduino, Crafts, Science, Digital Fabrication, Green, Transportation, Interaction and Young Makers (under 16);

e-Ink Displays – Underestimated Technology for Rough Industrial and Outdoor Interfaces

e-ink display in rough outdoor usage scenario

e-ink display in rough outdoor usage scenario, image source: http://www.eink.com

Since the first commercial appearance of e-Ink Displays around the year 2008, a large collection of cheap e-book readers, such as the Sony PRS505 or Amazon’s Kindle, were successfully introduced on the consumer market. As the e-Ink technology became mature in this field of application, millions of e-book readers are in active use today and the amount of sold e-books is nearly the same level as of traditional books.

E-Ink technology was first mentioned in 1997 based on research started at the MIT Media Lab. Joseph Jacobson and Barrett Comiskey are listed as inventors on the original patent filed in 1996.
E-Ink displays offer some great advantages over alternative display technology, such as extremely low power usage, incredible high contrast and the ability to preserve the static image for an unlimited amount of time without the use of any energy at all. E-Ink displays on the other hand do not offer much multimedia capabilities as they are mostly operating on grayscale, or very simple single color modes. Also their slow reaction times prevent e-Ink displays to show any videos.

Beside the widespread use of e-Ink displays in e-Ink ebook (or even as prototypical Smartphone display) reading devices, their use within industrial applications and rough production or outdoor scenarios is still underestimated. As e-Ink displays offer perfect contrast and preserve the displayed image over an unlimited amount of time, these displays could be the perfect choice for machine interfaces.
Following examples show the use of e-Ink displays in various interesting applications, such as static information on pillboxes, showing information directly on a mountain bike or even to directly show information on a snowboard.

e-Ink display on a pill box

e-Ink display on a pill box, image source: http://www.eink.com

e-ink display on a snowboard

e-ink display on a snowboard: image source: http://www.eink.com

Watch a short film explaining the basic concepts of e-Ink technology:

Augmented Reality Takes Off with Google Glass

Google’s Project Glass, the implementation of an augmented reality head-mounted display (HMD), has gained a lot of publicity over the last months. Recently, Google published some additional promotion videos that should demonstrate the benefit of these head-mounted transparent see through displays. Project Glass introduces the recording of personal activities in first person perspective, comarable with a helmet mounted action cam. Google Glass is also used as an unobstrusive information display, in order to give you additional background information in every situation of your daily life.

Arduino Controlled Magic Chess Board

This Arduino controlled Chess board set tangibly connects two players with each other from anywhere in the world. To combine physical interfaces to intuitively control virtual environments gives users the possibility to control all kinds of digital technology without much background knowledge. The combination of tangible artefacts with digital content is called ‘Tangible User Interfaces’. This amazing chess board game is a perfect example for such a tangible interface approach.

Plant Link – Smart Embedded Gardening for Everyone

Plant Link, recently started to fetch funding on Kickstarter tries to make your gardening a little bit smarter than usual. The inventors of Plant Link promise that by using their smart plant monitoring device even the biggest plant killers get a green thumb.
Plant Link is a hardware device that monitors the water needs of your lawn, garden, or house plants. It alerts you on your iPhone when your plants need to be watered and can even water them for you, at least for a while. Plant Link is designed for indoor as well as for outdoor use, just put it  beside a plant you would like to monitor. Plant Link is then acting as the ‘Big Brother’ for your plants as it is configured and paired exactly for one type of your plants, as each family of plants has different needs. It is even possible to log into the Blog of your plant to see if they are doing well or not. Plant Link perfectly follows the actual trend of green gardening technologies.

With Plant Link the Internet of Things is definitely growing into an Internet of Plants as well 😉

Adorable Lean Product Design: Activity Tracker Misfit Shine

Misfit Shine personal activity tracking device

Misfit Shine personal activity tracking device, image source: www.indiegogo.com/misfitshine

Its no surprise that the adorable lean product design of Misfit’s Shine personal activity tracker catched so much public attention that its Indiegogo pledge for funding reached nearly  $700.000 and exeeded its target value by around 600%! Misfit Shine is designed as a waterprove, durable and very light personal device that you can wear even if you go hiking or swimming. Shine is carved out of solid steel within one piece and wirelessly transmits your activity information onto your iPhone. In order to sync your devices data, just lay your Shine on your iPhone.

Misfit Shine offers a lean interaction design by just showing a circle of tiny leds that indicate your potion of activity for your day. The Misfit Shine personal activity tracking device now also is shipped in sleek matte black, which gives it an additional exclusive touch.

Lego announced next Generation Lego Mindstorms EV3

At this year CES, Lego just announced the next generation of Lego Mindstorms Educational robotic invention kits. Lego Mindstorms robotic educational kits are used by a large community of robotic hobbyists and the release of the next generation of their invention kit was a logic step. The new generation of Lego Mindstorm Kits is called Lego Mindstorms EV3 and will offer a deeper integration into the users consumer electronic, such as smartphones or digital cameras. Lego enhanced the new Lego Brick by adding more (16 MByte) Flash-Memory and (64 MByte) RAM, to offer the user more space for complex programming. In order to store sensor values or images on the Lego-Brick, Lego added a SD-Card slot. Lego also improved the 3D engineering experience by offering a new Creation software that is based upon the popular Autodesk suite, which enables the 3D engineering of Lego models and to provide a perspective view on your designs.