Giter Site home page Giter Site logo

lektion-23-april's Introduction

Smart Home API

Smart Home API Lab

ZoCom Smart Home API is a playground to learn API design and code with express.js. Download or fork this repo and get started!

Control the devices

To control the different devices in the frontend, all you need to do is to update the object in the db (lowdb) and call the update() function.

Ex.

db
.get('devices')
.find({ id : id })
.assign({ on : true }) // Turn on the device
.value();

update(); // tell frontend to update state.
db
.get('devices')
.find({ id : id })
.assign({ on : true, brightness: 0.5 }) // Turn on the device and change brightness
.value();

update(); // tell frontend to update state.

Changes in the db are synchronous.

Models

You can also view all of the devies datamodels in the about section on the frontend.

AC

{
  "id": String,
  "type": "AC",
  "name": String,
  "on": Boolean,
  "temperature": Number,
  "state": String // on, off
}

Blind

{
  "id": String,
  "type": "Blind",
  "name": String,
  "on": Boolean,
  "state": String // up, down
}

Light

{
  "id": String,
  "type": "Light",
  "name": String,
  "on": Boolean,
  "color": String, // #-code
  "brightness": Number, // 0-1
  "state": String // on, off
}

Vacuum

{
  "id": String,
  "type": "Vacuum",
  "name": String,
  "on": Boolean,
  "state": String // cleaning, charging, off
}

Lock

{
  "id": String,
  "type": "Lock",
  "name": String,
  "locked": Boolean,
  "secret": String, // UUID
  "code": Numbers // min 4 digit
}

Camera

{
  "id": String,
  "type": "Camera",
  "name": String,
  "on" : Boolean,
  "secret": String, // UUID
  "state" : "filming" // filming, faking
}

Speaker

{
  "id": String,
  "type": "Speaker",
  "name": String,
  "on" : Boolean,
  "stream": { 
    "file" : String, // .mp3, .ogg
    "name" : String
  },
  "state" : "silent" // silent, playing
}

Current devices and ID

Device type Id Comment
Vacuum VAC1 BB8 slow cousin
Light LIG1 Bedroom light
Light LIG2 Livingroom light
Light LIG3 Garden light
AC AC1 Air conditioner
Blind BLI1 Blinds
Lock LOC1 Smart lock
Camera CAM1 Camera
Speaker SPE1 Smart speaker

Level up

Fjärkontroll

Gör en snygg vanilla fjärrkontroll värdig ditt smarta hem. Den ska ha UI-kontroller till samtliga prylar.

Add more devices

You can even add more devices to expand your home by entering them ( by hand ) in the db/db.json file. Dont forget to give them a unique ID.

Happy experimenting!

lektion-23-april's People

Contributors

majazocom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.