Nizzies Home Automation Efforts: Difference between revisions

From NURDspace
No edit summary
No edit summary
Line 14: Line 14:
I followed this [https://home-assistant.io/getting-started/installation-raspberry-pi/ Installation instructions]. This worked fine once I installed some dependencies for the [https://home-assistant.io/components/discovery/ discovery component] (I don't know which one did the trick):
I followed this [https://home-assistant.io/getting-started/installation-raspberry-pi/ Installation instructions]. This worked fine once I installed some dependencies for the [https://home-assistant.io/components/discovery/ discovery component] (I don't know which one did the trick):
<pre>apt-get install build-essential checkinstall python3-dev</pre>
<pre>apt-get install build-essential checkinstall python3-dev</pre>
To have it autostart as a service, I use this /etc/init.d/hass-daemon script:
To get device tracking with nmap working, nmap needed to be installed and a symlink for arp needed to be made:
<pre>
apt-get install nmap
ln -s /usr/sbin/arp /usr/bin/arp
</pre>
To have home assistant autostart as a service, I use this /etc/init.d/hass-daemon script:
<pre>
<pre>
#!/bin/sh
#!/bin/sh

Revision as of 19:49, 4 November 2016

Nizzies Home Automation Efforts
Home-assistant.png
Participants Dennis
Skills 1337 Skillz
Status Active
Niche Electronics
Purpose Fun
Tool No
Location Niz
Cost
Tool category

Nizzies Home Automation Efforts

Home-assistant.png {{#if:No | [[Tool Owner::{{{ProjectParticipants}}} | }} {{#if:No | [[Tool Cost::{{{Cost}}} | }}

The brain: Banana Pro with Home Assistant

My Pi 2's micro sd card broke very quickly, so I've been working on a more stable replacement in the form of a Banana Pro board. I installed Bananian on the sd card and then moved the installation to a read hard disk connected to the SATA port. Hopefully this will survive longer.

Home Assistant

I followed this Installation instructions. This worked fine once I installed some dependencies for the discovery component (I don't know which one did the trick):

apt-get install build-essential checkinstall python3-dev

To get device tracking with nmap working, nmap needed to be installed and a symlink for arp needed to be made:

apt-get install nmap
ln -s /usr/sbin/arp /usr/bin/arp

To have home assistant autostart as a service, I use this /etc/init.d/hass-daemon script:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          hass
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       Home\ Assistant
### END INIT INFO

PRE_EXEC="python3 -m venv /srv/homeassistant/homeassistant_venv && . /srv/homeassistant/homeassistant_venv/bin/activate;"
RUN_AS="homeassistant"
PID_FILE="/var/run/hass.pid"
CONFIG_DIR="/home/homeassistant/.homeassistant"
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
REDIRECT="> $CONFIG_DIR/home-assistant.log 2>&1"

start() {
  if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
    echo 'Service already running' >&2
    return 1
  fi
  echo 'Starting service…' >&2
  local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
  su -c "$CMD" $RUN_AS
  echo 'Service started' >&2
}

stop() {
    if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then
    echo 'Service not running' >&2
    return 1
  fi
  echo 'Stopping service…' >&2
  kill $(cat "$PID_FILE")
  while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;
  echo 'Service stopped' >&2
}

install() {
    echo "Installing Home Assistant Daemon (hass-daemon)"
    echo "999999" > $PID_FILE
    chown $RUN_AS $PID_FILE
    mkdir -p $CONFIG_DIR
    chown $RUN_AS $CONFIG_DIR
}

uninstall() {
  echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  local SURE
  read SURE
  if [ "$SURE" = "yes" ]; then
    stop
    rm -fv "$PID_FILE"
    echo "Notice: The config directory has not been removed"
    echo $CONFIG_DIR
    update-rc.d -f hass-daemon remove
    rm -fv "$0"
    echo "Home Assistant Daemon has been removed. Home Assistant is still installed."
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  install)
    install
    ;;
  uninstall)
    uninstall
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|install|uninstall}"
esac

Now we need to enable this:

update-rc.d hass-daemon defaults
service hass-daemon install

From now on the service will autostart when machine boots, and can be started and stoppen with:

service hass-daemon start
service hass-daemon stop

Sensors

NRF nodes

Most probably I will use the hardware designed by User:Zarya as mentioned in NrfSensorNode. They will run the library from https://www.mysensors.org/.

Lights

Philips Hue

Got some Philips Hue stuff for cheap. It's the Hue Bridge v1, and 3 LED lights that work just fine, although 2 of them are missing the glass bit. They do whites and colors \o/. They are supposed to integrate with Home Assistant very easily: https://home-assistant.io/components/light.hue/ <gallery> Image:Hue.jpg </gallery?