Controling Homeautomation devices using wifi presence

From BubbaWiki
Jump to navigation Jump to search

This guide is not finished yet. I'm working on it :-)

#!/bin/bash

HomeAutomationUrl="http://192.168.168.1/homeautomation/"

# Devices that affects HomeAutomation
homeDevices[0]="84:00:d2:e4:3b:9f" #Xperia Ray
homeDevices[1]="d0:df:c7:fd:8d:ea" #Galaxy Tab

# HomeAutomation device ids
HomeAutomationDeviceIds[0]="20" #Xperia Ray
HomeAutomationDeviceIds[1]="21" #Galaxy Tab

connected="AP-STA-CONNECTED"
disconnected="AP-STA-DISCONNECTED"

countHomeDevices=${#homeDevices[*]}

date >> /var/log/hostapd.log

for (( i=0; i<=$(( $countHomeDevices -1 )); i++ )); do

  if [ $3 = "${homeDevices[$i]}" ]; then

    connectionState=0

    if [ $2 = $connected ]; then
      connectionState=1
      echo "$3 Connected!" >> /var/log/hostapd.log
    else if [ $2 = $disconnected ]; then
        echo "$3 Disconnected" >> /var/log/hostapd.log
      else
        echo "What happened now?" >> /var/log/hostapd.log
      fi
    fi

    $(wget -O /dev/null -q ""${HomeAutomationUrl}"ajaxinterface.php?do=toggleStatus&status="${connectionState}"&deviceid="${HomeAutomationDeviceIds[$i]}"" )
  fi

done