Skip to content

nelsonchen90/HomeAutomation

Repository files navigation

HomeAutomation

A Home automation sever running on Raspberry Pi 3B with Raspberry Pi OS Lite

Interaction

UI:

  • http://{hostname}
    • in production mode, there will be 2 ports being listened. 80 for http redirect and 443 for https
    • using Certbot to generate certificates, need to renew periodically
    • check my running site here: homeautomationbox.com

Alexa:

  • What is Alexa?
  • Deployed as a privite skill on Alexa under name: Decor light. Access skill here
    • utterances:
      • turn on/off decor light
      • decor light on/off
      • decor light switch
      • help
      • what is this
      • what does this do
      • ...

Documentation

Installation/dev

  • installation: npm i
  • start dev db: use dynamodb-local
    • docker installed locally
    • cd to ./db and run docker-compose up -d. It will download the docker image if not exists and start the container in the background
  • start server and UI dev: npm run dev

Production

  • start server: npm run start
  • DB: AWS DynamoDB (us-east-1)
  • create service so can boot with OS https://stackoverflow.com/a/29042953 (Will change once containerized)
    • sample service file under .utils/homeAutomation.service. Please read thru it for it has token/secret needs to be generated
  • to use aws dynamo db, have the credentials under ~/.aws/credentials.
    • to generate users table in the initial load run production with env var: INIT_DB=true

Auth

  • Technology:
    • Using bcrypt for hashing/verification. So no actual password is saved
    • Using JWT for validating logged-in user
  • REST:
    • body:
        {
          "username": "username",
          "password": "password
        }
      
    • login: POST {hostname}/auth/login
    • signup: POST {hostname}/auth/signup (TBD) need to improve

USB port power

  • preqeq: Install and setup (permission) uhubctl https://github.com/mvp/uhubctl

  • symlink the uhubctl to /usr/local/bin so the child_process can access

    ln -s /usr/sbin/uhubctl /usr/local/bin/uhubctl
    

    REST API:

    • status: GET {hostname}/api/v1/usbSwitch/status
    • turn on/off: GET {hostname}/api/v1/usbSwitch/on / GET {hostname}/api/v1/usbSwitch/off

Wake on lan (WOL):

  • prereq: WOL with magic packet must be enabled on the device prior using this feature. For Windows check here

    REST API:

    • trigger on: POST {hostname}/api/v1/windowsSwitch/toggle

      // body optional. it will override the one defined in env variable when provided 
      {
        "targetMacAddress": "1A:2B:3C:4D:5E:6F"
      }