Skip to content

My own little home automation API for controlling lights, power outlets, shutters, etc.

License

Notifications You must be signed in to change notification settings

chrisEff/home-server-nodejs

Repository files navigation

Home Server

GitHub license CI Coverage Status Known Vulnerabilities

This server provides a simple little REST API that allows you to

  • control Ikea Trådfri lights by connecting to a Trådfri gateway
  • switch 433 MHz radio controlled power outlets on and off

Requirements

If you want to control Ikea Trådfri lights, you'll need...

  • at least one bulb (duh!)
  • an Ikea Trådfri gateway, connected to the same network as the computer this software runs on

If you want to control 433 MHz power outlets, you'll need...

Installation

(Assuming you're using a Raspberry Pi with a freshly installed Raspbian. Under other circumstances, some steps might be slightly different or even obsolete.)

  • install git

    sudo apt install git
    
  • install node.js v12.x

    wget https://deb.nodesource.com/setup_12.x
    chmod +x setup_12.x
    sudo ./setup_12.x
    sudo apt install nodejs
    

    For more info see: https://github.com/nodesource/distributions#debinstall

  • install WiringPi

    git clone git://git.drogon.net/wiringPi
    cd wiringPi
    ./build
    cd ..
    

    For more info see: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

  • clone this repo with its submodules:

    git clone --recursive git@github.com:chrisEff/home-server-nodejs.git
    
  • install the dependencies:

    cd home-server-nodejs
    npm i --production
    
  • compile RPi_utils

    cd 433Utils/RPi_utils
    make
    cd ../..
    
  • adjust config.js according to your needs

  • allow node to bind ports < 1024 (dhcp-spy needs to listen on port 67 in order to detect DHCP requests from dash buttons):

    npm run allow-portbind
    
  • enable reading DS18B20 temperature sensors via W1 bus:

    sudo su
    echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> /boot/config.txt
    echo 'w1-gpio pullup=1' >> /etc/modules
    echo 'w1-therm' >> /etc/modules
    reboot
    

    For more info see (german): https://www.kompf.de/weather/pionewiremini.html

  • start the server

    npm start
    

Useful links

Tradfri

433 Mhz

Temperature Sensors

coap-client Examples

get PSK

coap-client -m post -u "Client_identity" -k "<KEY_FROM_GATEWAY>" -e '{"9090":""}' "coaps://<GATEWAY_IP>:5684/15011/9063"

get gateway details

coap-client -m get -u "" -k "" "coaps://<GATEWAY_IP>:5684/15011/15012"

get list of device IDs

coap-client -m get -u "" -k "" "coaps://<GATEWAY_IP>:5684/15001"

get list of group IDs

coap-client -m get -u "" -k "" "coaps://<GATEWAY_IP>:5684/15004"

get device infos

coap-client -m get -u "" -k "" "coaps://<GATEWAY_IP>:5684/15001/<DEVICE_ID>"

get group infos

coap-client -m get -u "" -k "" "coaps://<GATEWAY_IP>:5684/15004/<GROUP_ID>"

turn bulb on

coap-client -m put -u "" -k "" -e '{ "3311" : [{ "5850" : 1 }] }' "coaps://<GATEWAY_IP>:5684/15001/<DEVICE_ID>"

turn bulb off

coap-client -m put -u "" -k "" -e '{ "3311" : [{ "5850" : 0 }] }' "coaps://<GATEWAY_IP>:5684/15001/<DEVICE_ID>"

set bulb to warm white

coap-client -m put -u "" -k "" -e '{ "3311" : [{ "5706" : "efd275" }] }' "coaps://<GATEWAY_IP>:5684/15001/<DEVICE_ID>"

rename bulb to "foobar"

coap-client -m put -u "" -k "" -e '{ "9001" : "foobar" }' "coaps://<GATEWAY_IP>:5684/15001/<DEVICE_ID>"

About

My own little home automation API for controlling lights, power outlets, shutters, etc.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published