BME680 Home Assistant Integration

Hi 👋,

In this short article I will highlight how to use the BME680 Home Assistant integration with a BME680 Sensor.

Please note that I’m running Home Assistant core on Raspbian OS.

Raspberry Pi Setup

Before connecting the sensor, you will need to enable the I2C interface on your Raspberry Pi and install some additional tools that are useful for debugging.

To enable the I2C interface execute:

sudo raspi-config

Then go to Interfacing options->I2C and select yes.

Next, install the following packages:

sudo apt-get install build-essential libi2c-dev i2c-tools python-dev libffi-dev

Sensor Setup

The first step is to buy the sensor, get one with headers already soldered if you can otherwise, you’ll need to solder them.

I got mine from Pimoroni and I’ve never was disappointed by them, they deliver to EU.

BME680 sensor. Pimoroni screen capture 2022-01-16

Next depending on which headers you’ve chosen; you will need four male-to-female jumper wires to connect the BME680 to the Raspberry Pi.

To connect the sensor to the Raspberry PI, refer to the following diagram:

You will need to connect the wires to the following buses:

  • Sensor Power -> Raspberry PI 3.3V
  • Sensor GND -> Raspberry PI GND
  • Sensor SCL -> Raspberry PI SCL
  • Sensor SDA -> Raspberry PI SDA

Check that the sensor is detected using the following command on the Raspberry Pi.

/usr/sbin/i2cdetect -y 1

You should get an ouput like this:

0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 76

The sensor’s I2C address can be 0x76 or 0x77. According to the above output, the sensor address in our case is 0x76, keep this in mind.

Home Assistant Setup

Add your homeassistant user to the I2C group by running:

sudo addgroup homeassistant i2c

Next, open configuration.yaml and modify the sensor and homeassistant.customize sections according to:

Don’t forget to replace i2c_address : 0x76 with your i2c address if it’s different.

homeassistant:
  name: HomeKit NucuLabs
  unit_system: metric
  time_zone: Europe/Bucharest
  customize:
    sensor.bme680_sensor_temperature:
      icon: mdi:thermometer
      friendly_name: Temperature
    sensor.bme680_sensor_humidity:
      icon: mdi:water
      friendly_name: Humidity
      device_class: humidity
      unit_of_measurement: "%"
    sensor.bme680_sensor_pressure:
      icon: mdi:gauge
      friendly_name: Pressure
    sensor.bme680_sensor_air_quality:
      icon: mdi:blur
      friendly_name: Air Quality
      device_class: pm25
      unit_of_measurement: "%"

sensor:
  - platform: bme680
    i2c_address: 0x76
    monitored_conditions:
      - temperature
      - humidity
      - pressure
      - gas
      - airquality

Reboot the device after you’ve modified configuration.yaml by running sudo reboot.

Note: The customize section sensor.bme680_sensor_air_quality sets the device class of BME680 air quality measurement to pm25, but this isn’t a pm25 measurement, it’s a proprietary algorithm according BME680 Datasheet. High values indicate good air quality while low values indicate low air quality. On the other hand, in pm25 measurements high values indicate bad air quality and low values good air quality.

This is a hack and it’s up to you if you want to keep it. If you don’t set the device class to pm25 then the measurement won’t be visible in Apple Homekit because Homekit is not aware of this kind of measurement. If you know any other way of making it visible in Homekit let me know. 😀

After home assistant reboots, the following entities should be available in the Lovelace UI:

Thanks for reading! 🍻

Home automation with Home Assistant on Raspberry PI – Getting Started

Hi 👋

The purpose of this article is to get you started quickly with a Home Assistant on a Raspberry Pi. It’s a simple walkthrough on how to install Home Assistant and configure it so it will boot with your PI.

I will use my old Raspberry PI V3 board.

Flashing the Raspberry PI OS

You will need a microSD card of reasonable size, I’m using a 16GB one and a USB Adapter to connect it with my PC.

Head over to Raspberry Pi OS website and download your preferred image, for my Home Assistant I’ve chosen Raspberry Pi OS with desktop and recommended software. After the download is completed, unzip the file and prepare to flash it.

To flash the OS image on the SD card I will use a program called balenaEtcher.

Download it, select your OS image, select the SD card, and hit flash.

After SD card flashing finishes, it is time to setup the Wi-Fi connection. If you’re using an ethernet cable you can skip this step, however, remember to enable SSH.

Setting up the Wi-Fi and enabling SSH

Unplug the SD card from the computer and plug it back. You should see two new drives D: and E:

  1. Open your favorite text editor and create an empty file called ssh in drive E:. This will enable SSH access.
  2. Create a new file called wpa_supplicant.conf using your text editor and paste the following contents in it:
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
   scan_ssid=1
   ssid="YOUR_WIFI_SSID"
   psk="YOUR_WIFI_PASSWORD"
}

Don’t forget to replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with the corresponding values regarding your Wi-Fi network.

Eject the SD card from your computer and plug it into the PI. At boot, the PI should automatically connect to your Wi-Fi network.

Installing Home Assistant Core

Find your Raspberry PI’s IP address and connect to it via ssh. You can run the command ssh pi@192.168.0.XXX. The password for the pi user should be raspberry.

After getting a shell, follow the instructions for installing Home Assistant from the official website.

Ensure that you run each command on its own line. Don’t directly copy the entire code block, copy each line individually.

Starting Home Assistant on boot

If you can access the Home Assistant web GUI using http://192.168.0.XXX:8123 then the next step would be to create a new systemd service so that some assistant starts at boot. Please replace XXX with your Raspberry PI’s IP address.

To create a new service:

  1. Start a new shell on the Raspberry or ensure that you’re using the pi user. We will execute commands with sudo.
  2. Use sudo nano /etc/systemd/system/hass.service to create a new file and paste the following contents into it:
[Unit]
Description=HomeAssistant Service
After=network.target

[Service]
User=homeassistant
WorkingDirectory=/home/homeassistant
Environment="PATH=$PATH:/srv/homeassistant/bin"
ExecStart=/srv/homeassistant/bin/hass

[Install]
WantedBy=multi-user.target

Stop hass command if it’s running and enables the service by executing:

sudo systemctl start hass.service
sudo systemctl enable hass.service
sudo systemctl status hass.service

If the service is running normally, everything is set up. You can safely reboot your PI and the Home Assistant service will run after boot.

Configuring Home Assistant

When visiting the Home Assistant’s web interface for the first time, you will be prompted to create a new user. You may also download the Home Assistant application for your mobile device if you wish to track things like battery, storage, steps, location and so on, in Home Assistant.

In future articles I will show you how to configure the BME680 enviromental sensor and how to activate the Apple Homekit integration. Until then, have fun exploring Home Assistant docs.

Things to do further:

Unattended Upgrades – Enable unattended upgrades for your Raspbian OS. Ensures that your OS’s is always patched and up to date.

UFW – Secure your Home Assistant server with the uncomplicated firewall.

Change default passwords or disable SSH login via password.

Thanks for reading and happy automations! 📚

My Homelab Journey: Introduction

Hello everyone!

After following the /r/homelab reddit for a while I’ve decided to give it a try and make myself my own homelab environment. I don’t have access to expensive server equipment nor do I have the means to acquire it, so I will be using an old HP Laptop which has quite a few resources, it is a bit stronger than the average Raspberry PI.

The laptop has 11GB of RAM memory, a 740GB disk and an Intel i7-4702MQ CPU. I have it for almost 4 years now and I’ve only used it for a few months, I decided to re-purpose it. If you’re asking yourself why didn’t I used the laptop, well, the laptop is absolutely horrible to work with! HP has made a terrible consumer product, it wasn’t targeted to business users and it is sluggish (with windows) and made of cheap plastic. On Windows HP has failed to provide basic working drivers, the laptop freezes every minute or so.

The Busy Server

This will be the name of my new server Busy Server. The name was chosen because I plan to host all the services on this machine, for now.

For starting I’m going to put a DNS server, an OpenSSH server, an FTP server and a media server. In the future I’ll think about other services that might benefit me.

The DNS server’s purpose is to allow me to access the other resources in a more friendly manner, like ftp.busyserver.net instead if 192.168.0.*

The FTP server will be an anonymous server to facilitate easy file sharing in the local network, it won’t have any outside access.

The media server will be unused, for now. A potential use case for it would be to get a Chromecast and use it to watch movies together with my family, but I’m not even sure if I need a media server.

Cloud Services

I currently still rely on multiple cloud services for work.

There’s a few cloud services that I like a lot and I use them daily. I’m not ready to make the move from them to my own self-hosted alternatives. Some of these services are Trello, Slack, Dropbox, Github and Evernote.

Trello is a great tool for productivity, it gives me space to host my scrum boards, I don’t do any planning on it although I’ve heard about people that follow an agile lifestyle and plan their entire month using agile boards. I use Trello mostly to store programming notes and other technical stuff. I like the fact that I can invite other people to my boards and collaborate with them, but a huge turn-off is that it feels a bit weird to use when storing large notes, it’s not really meant for reading but I guess it could do for now. A replacement for it would be a 10$ Jira server license or another alternative.

Dropbox is the place where is store all the files that I need to take with me. Those files can be documents, books, software licenses and small programs. Of course they are encrypted with my personal GPG key so don’t even think about it.

While Slack is quite new to the scene, I’m thinking in making my own private work-space that I’ll share with my family members and perhaps close friends. In the future, I will attempt to compliment this with custom Slack apps, that will aid in home automation and status reporting, it’s going to be fun.

Evernote is my standard application for taking notes, it’s not perfect, but it works. I’m not going to pay for it (ever), I’d rather use simple markdown files if it goes this far. Evernote could be replaced with a MediaWiki or DokuWiki but since I rely on my notes a lot this won’t happen very soon.

Those are my plans for now, I also have a nice VPN raspberry pi server setup that allows me to access my LAN network from outside.

What do you think about my plans? Do you I could make use of other interesting services? Let me know in the comments if so.

Thank you for reading and have a nice day!