The embryo of a home automation system

2019-03-16

Here is a short description of my home automation system. Currently, there isn’t much automation to speak of, but I have ordered some stepper motors and Arduino microcontrollers from China, so whenever they arrive (if they do) I will put in some effort to automate the operation of some valves today taken care of manually twice a day. Until then, I have only set up logging of temperatures at different places around the house.

That being said, the basis of my system is a Dell PowerEdge T20 server running Unraid, which is a Slackware based operating system that manages storage with parity protection and caching like RAID, while also functioning as an application and database server and type 2 hypervisor. On the server, I run lots of Docker containers for different purposes: Nextcloud (a self-hosted Dropbox alternative), Plex media server for streaming movies and tv series to my tv, tablets or phone; different databases (relational like Postgres and MariaDB and the time-series database InfluxDb; more on that later), CrashPlan (backup management), Grafana for visualizing data, and more.

On the server I also run a virtual Ubuntu Server host (named enclave: the Unraid hostname is vault13 if anyone gets the reference) that is supposed to function as the brain in my home automation system. I have connected a USB device (DS9490R) for 1-wire communication with my temperature sensors (DS18B20 and TC2 [based on DS2762] for thermocouple type K). The USB device is passtrough’d to enclave where I have installed owfs to mount the 1-wire sensors in the file system in a more structured manner (before, I just used the w1 driver).

On enclave I run Home Assistant. It was quite easy to get it running and the DS18B20 sensors were found automatically just by adding the platform “onewire” under the sensor scope in the config file:


sensor:
  - platform: onewire
    mount_dir: "/mnt/1wire"
    names: # These are just friendly names 
      28.FF31AA651803: pannrum
      28.FF57AA651803: utomhus
      30.8C23D3120000: rökgas
      28.FF4EA7651803: ackumulatortank_övre
      28.FF87AB651803: matkällare
 

The thermocouple did not show up however, so I had to modify the onewire.py file; but for the sake of order and sanity, I copied the file to a custom component with the same name, and made the necessary modifications locally.

""" 
   ~/.homeassistant/custom_components/onewire/sensor.py 
   A copy of
   ~/.virtualenvs/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/onewire.py
   Everything unchanged except the DEVICE_SENSORS dictionary that now looks like
   this

"""

DEVICE_SENSORS = {'10': {'temperature': 'temperature'},
                  '12': {'temperature': 'TAI8570/temperature',
                         'pressure': 'TAI8570/pressure'},
                  '22': {'temperature': 'temperature'},
                  '26': {'temperature': 'temperature',
                         'humidity': 'humidity',
                         'pressure': 'B1-R1-A/pressure',
                         'illuminance': 'S3-R1-A/illuminance'},
                  '28': {'temperature': 'temperature'},
                  '30': {'temperature': 'typeK/temperature'}, # This one is added
                  '3B': {'temperature': 'temperature'},
                  '42': {'temperature': 'temperature'}}

Before installing Home Assistant, I used a simple python script executed periodically by cron to store the temperatures in a csv file. I then used a Jupyter notebook and Pandas to read the temperatures and plot them. Now, I’ve started to use InfluxDb for storing data instead and Grafana for visualizing. Home Assistant is set up to read the temperatures from the file system and store the values in InfluxDb. This was decided before I knew that Home Assistant has native support for this, which made it very easy! Here’s all I needed to add in the configuration.yaml file:

influxdb:
  host: vault13 # the hostname or ip address where InfluxDB is running
  include:
    entities:
      - sensor.utomhus_temperature
      - sensor.pannrum_temperature
      - sensor.matkallare_temperature
      - sensor.ackumulatortank_ovre_temperature
      - sensor.rokgas_temperature

The names of the entities can be found in the web interface by clicking on the < > button or going to <ip-address:port>/dev-state.

In Home Assistant, I’ve configured a command_line sensor that continuously saves a snapshot of a Grafana plot as a .png file, and this is shown on the start page by treating it as a camera.

There are lots of things to fiddle with and I have yet to come up with what I really want to achieve with my home automation. But I struggle not to realize that starting a process like this one is like opening Pandora’s box; soon enough, the rational explanations to why investing time and money on home automation is a feasible thing, will get pushed down by the fear of not automating enough, and the psychosis of engineering sets in and the squirrel cage starts to spin faster and faster.

But does it really matter? No. I will wait for my stepper motors and if things go wrong, the next project may be DIY anti-psychosis drugs by extracting lithium from batteries. ¯\_(ツ)_/¯