Coder Social home page Coder Social logo

mismarthomeapi's Introduction

SmartHomeAPI

基于PyXiaomiGateway,python-miio,Django后端的小米智能家居RESTful HTTP API。

项目定位

仅小米设备而言,我们目前买到的设备有如下几种设备:

  • chuangmi.plug.m3 创米插座(需要使用python-miio库)
  • zhimi.airpurifier.ma2 智米空气净化器(支持python-miio)
  • zhimi.fan.za4 智米风扇(支持python-miio)
  • yeelink.light.lamp1 Yeelink台灯(python-miio库支持简单操作,复杂操作需要python-yeelight库)
  • lumi.gateway.v3 绿米网关(需要使用PyXiaomiGateway库)
  • weather.v1 Aqara温湿度传感器(支持PyXiaomiGateway)
  • magnet 门窗传感器(支持PyXiaomiGateway)
  • 米家蓝牙温湿度计 不支持米家普通网关控制(需要使用特殊的蓝牙网关,比如米家床头灯,米家1090P智能摄像机,yeelight智能LED吸顶灯等)

智能家居目前没有一个统一的协议,就算是同一家公司的设备也多种多样。随着设备的增加会变得越来越复杂,个人基本无法完成,最好是借助其他较为完善的平台进行改造开发。

但我们仅基于有限的设备做几个demo cases,不需要考虑所有设备。

参考home assistant:

  • 采用轮询方式更新设备信息。受限于设备单向通信问题(手动变更设备状态,设备不会发送变更信息给主机),采用轮询来更新主机上设备信息。
  • 设备token和网关密码等需要用户自己获取(可能有帮助:https://github.com/xcray/miio-by-CSharp)。
    • 获取token手段:使用Android手机下载米家APP(v5.4.49),用APP连接设备后,token以明文形式记录在APP的log文件(/SmartHome/logs/\d{4}-\d{2}-\d{2}\.txt)中。
    • 获取网关密码信息:在米家APP中打开开发者模式获取信息。

目前实现

  • 定时监控局域网中的智能设备(需要被python-miio支持)和传感器(需要被PyXiaomiGateway支持)
  • 以REST APIs形式访问支持Wi-Fi的米家智能设备(控制开关)和传感器(获取状态)
  • 支持将监控数据上传到远程数据库

环境要求

使用

  1. 安装环境

    sh build.sh
  2. 修改配置

    mv smartHomeApis/config.example.py smartHomeApis/config.py

    并编辑smartHomeApis/config.py进行配置。

  3. 运行后端

    python manage.py runserver 0.0.0.0:8000
  4. 运行demo

    python demo.py

接口设计

访问/help显示如下接口文档:

PUT
    - Description:  Add a device.
    - Path:
        /<str:did>
    - Form:
        @localip    IP address of device in LAN
        @token      Device token, which is allocated when the device connects to MI-HOME app
        @name       Device name which is generally set in MI-HOME app (not necessary)
GET
    - Description:  List terminals(include devices and sensors) infomation.
    - Path:
        /           List all terminals infomation
        /<int:tid>  List terminal infomation corresponding to the tid
DELETE
    - Description:  Delete a terminal by tid.
    - Path:
        /<int:tid>
POST
    - Description:  Given instructions, control device(Default switch on and off status).
    - Path:
        /<int:did>
    - Form:
        @status     0 or 1(not necessary)

注意

  1. 由于可以通过GET方法直接获取每个注册设备的信息,存在严重的安全隐患。
  2. 后端会持续将设备信息发送到数据库,存在严重的隐私安全隐患。
  3. 设备的插拔不会改变localip与token,设备的重置会改变token。
  4. 不同传感器数据更新时间不同,如门窗传感器每秒更新,而温度传感器每十秒更新。

mismarthomeapi's People

Contributors

barrierye avatar

Stargazers

 avatar  avatar BowenDeng avatar  avatar  avatar Dray avatar  avatar  avatar TalexDreamSoul avatar  avatar bio avatar Nickming avatar Too large to fit in the margin avatar arg0 avatar CatttttttttttttttttttttttttttM avatar  avatar  avatar  avatar zengkaimin avatar

Watchers

James Cloos 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.