If you are anything like me, then you have a range of commercial and home-made smart-devices (and some smartified ones) around the home. Some can be controlled via IR, some via HTTP or PHP, some via SSH or python.
Controlling this many devices I wanted to have a simple interface to control them all and not worry about how to talk to each one.
My smart-home setup already contained a raspberry pi 3 B, running lirc to control many of the formerly dumb devices like AC, projector and speakers. So I picked this device as my hub and created a bash-script which hides away all the specific control-protocols to the different devices.
After adding more devices it grew into a little bash-framework with Modules each serving one protocol.
Goals- Unified command line interface for multiple different protocols
- Extendable with additional protocols
- Easy configuration
- Easy hackability / extensions
The code I wrote I called homeAutomat ["Automat" german for "Automaton"]. If you want to run this hub as well, follow these easy step:
1. Download the codeThe code is accessible on Github. Since it is all implemented as a bash script it does not need ans installation. Simple download or clone the code unto the device you are using as a hub.
cd ~
git clone https://github.com/DFranzen/homeAutomat.git
Additional required lbraries for some of the plugins are listed on the github-page.
2. Enable connections checkFor IP-lookup and for automatically connecting to SSH devices, a script connectioncheck.sh needs to be executed periodically. The easiest way to achieve this is to add it to the crontab to be executed every minute.
crontab -e
Choose a editor and then add the following line at the end of the file:
* * * * * ~/homeAutomat/connectionCheck.sh
3. ConfigurationThe configuration is stored in a file ha.conf (not checked into the git repository). An example file is provided as ha.conf.example. For each device you want to control via the hub, you need to add the name to the list devices
and you need to add one configuration-block to deviceList
in this file.
First the ha.conf contains a few general settings:
- ha_user: name of the local user the homeAutomat should execute commands as (e.g. pi)
- primary_iface: Name of the network interface, network devices should be contacted (e.g. eth0)
The main part of the configuration are the configurations of the devices. The main settings are:
- type: The protocol with which this device should be handled.
- ips: The IP addresses for this device, devided by |
- macs: The MAC addresses for this device, devided by |. The MAC is used for WakeOnLan and to reverse-lookup the ip, if non is given
- wol: Set to any value, if the device supports WakeOnLan
- playback: Set to any value, if this device should be considered for playback
Some parameters are dependent on the plugin:
- user [SSH]: Name of the remote user
- cmd [http, pathon]: path/script that should be executed for every send command of this device (replacing the ip of the device by __IP__ and the command by __CMD__).
Additionally any device might overwrite some commands. This is done by setting the overwritten command to DEVICE|cmd|CMD, where DEVICE is the name of the device and CMD is the command that should be executed. e.g.
deviceList[laptop|cmd|mute]="xdotool key XF86AudioMute"
Also for lirc devices the number of repetitions for any device can be set by setting a number to DEVICE|CMD|repeat, where DEVICE is the name of the device and CMD is the command that sould be executed multiple times, when requested. e.g.
deviceList[speaker|VOLUME_UP|repeat]=2
4. SSH-connectionsDevices of the type "ssh
" need a bit of setup before the first use:
When connecting to a new ssh device for the first time, ssh confirms, that the fingerprint of this device is correct to avoid connecting to a malicious device. homeAutomat does not confirm new fingerprints, but aborts connecting to unknown devices. Therefore for each device you need to connect once and confirm the fingerprint manually by calling ssh <user>@<ip>
, e.g.
ssh pi@192.168.1.2
You will get the following output, which you need to confirm with "yes
".
The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
ECDSA key fingerprint is aa:bb:cc:...
Are you sure you want to continue connecting (yes/no)?
Even though homeAutomat can take a password in the configuration for SSH devices, it is easier to autheticate via RSA. To start using RSA-authentication for SSH connections, first you need to create a new RSA-key with the following command on the computer, which runs homeAutomat:
ssh-keygen
Passphrases are not supported with homeAutomat, so you will have to hit Enter without entering anything, when that question comes up.
Afterwards for each device you want to connect to, you need to install this new key with the following command on the homeAutomat computer:
ssh-copy-id <user>@<ip>
E.g.
ssh-copy-id pi@192.168.1.2
and enter the password to login o the SSH device once. After this is done homeAutomat can send commands to the SSH device without the need for a password.
UsageOnce the configuration is finished the script added to the crontab will try to establish SSH-connections to all ssh-capable devices and maintain them. Sending a command is then as easy as calling the script send.sh with the device-name as given in the config and the command. e.g. to send the command "xdotool click 1
" to the device laptop we call
./send.sh laptop xdotool click 1
If you have configured an alias for a command (as the command mute above), you can simply call the alias e.g.
./send.sh laptop mute
This works just as well with lirc devices e.g. to send the power-key to the device speaker:
./send.sh speaker KEY_POWER
As a bonus homeAutomat keeps track of a virtual device __CURRENT__
. Commands send to this device are always forwarded o the last-used, available device, which is marked with playback
in the configuration.
It also provides a few virtual commands like __PLAY__
, __PAUSE__
, __ON__
, __OFF__
and __FULLSCREEN__
, which are translated into reasonable commands for each type of device. So to continue the current media-playback on the last used device simply use:
./send.sh __CURRENT__ __PLAY__
My devicesHere is an inspiration what you can do with the homeAutomat. I am using this hub (apart from other devices) for my home cinema with the following devices:
- homeCinemaPi: A Raspberry Pi running the homeAutomat hub.
- homeCinemaLaptop: An old laptop, which plays DVDs and is connected via SSH
- projector: A projector connected to the laptop. homeAutomat controls it via an IR-diode taped to it.
- speaker: A 5.1 speaker system connected to the laptop. homeAutomat controls it via an IR-diode taped to it.
- acCarrier: an AC by carrier that is connected via an IR-Diode.
- tv: a ASUS TV which can be controlled via viera/IP
- lamp: a SOnOff switch running tasmota, controlled via http-requests
On the other side, there are the devices I use to trigger commands on the hub:
- Alexa: The same raspberry running homeAutomat also runs HA Bridge. For Alexa every command looks like a lightbulb and thus I can control all my devices e.g. with "Alea, switch movie on"
- Android: The Android APP Home Remote Control can call the send.sh script via SSH. This way all SmartHome Devices configured with homeAutomat can be controlled from your phone. As an added benefit this way the Mouse and Keyboard control in HomeRemote can always be send the
__CURRENT__
device.
Comments
Please log in or sign up to comment.