download only once
fallback for stop video
use correct sound output for video player
This repository contains part of my home automation configuration.
Though I'm using Home Assistant on the central server at the heart of my home automation (configuration here), I have various Raspberry Pis and other devices that are an integral part my home automation system.
To keep things on the various devices as lightweight and as portable as possible, I wrote 'lighthome'. It consists of various shell scripts and some simple programs to read/write several sensors. Central in the communication between all devices is the MQTT broker.
scripts/common/include.sh
- Defines common functions, including:
mqtt_receiver *[handlers]*
- Subscribes to MQTT and registers one or more handler scripts, takes care of reconnect logic in case of failures, parallelisation, and runs asynchronouslymqtt_transmitter *[topic] [interval] [sender]*
- Takes input and publishes it on MQTT, takes care of reconnect logic in case of failures, parallelisation, and runs asynchronouslymqttpub *[topic]* *[payload]*
- Publish a single MQTT messagescripts/mqtthandlers/*
) - Receives MQTT stream on standard input and should invoke scripts that perform the action by calling an action script.
mqttpub
)scripts/mqttsenders/*
) - Monitors some device/sensor (preferably via an independent action script or program) and then translates its output for MQTT (standard output)
scripts/
, programs/
) - Perform any action, completely MQTT unaware, can also be invoked independently from command line for low-level testingsetup-raspberry-pi.sh
- Script to setup raspberry pi. For headless setup, first sudo touch /boot/ssh
on the image, and add a /boot/userconf.txt
with contents homeautomation:$encryptedpw
where the password is encrypted with openssl passwd -6
.I decided on simple shell scripts to act as the glue between components and not opt for another layer in for example Python. In true UNIX-fashion each tool should have a well defined task, be efficient, communicate over standard input and output, and not add any unnecessary complexity. I also tried to separate the MQTT-logic from the logic addressing various sensors, so the latter can also be used independently.
The actual communication with MQTT is done via the excellent
mosquitto CLI clients (mosquitto_sub
and
mosquitto_pub
) communicating with the mosquitto daemon running on the main server.
Initially I ran Home Assistant on these devices as well, but due to their decision to remove GPIO support and the increased amount of unnecessary bloat which I don't need, I desired to go for a more lightweight approach and just write things from scratch.