项目作者: mnsn

项目描述 :
This app provides a simple server for controlling broadlink devices from google home.
高级语言: JavaScript
项目地址: git://github.com/mnsn/broadlink-mqtt-server.git
创建时间: 2019-01-02T22:27:36Z
项目社区:https://github.com/mnsn/broadlink-mqtt-server

开源协议:MIT License

下载


Node js app for home automation with broadlink and google home

This app provides a simple server for controlling broadlink devices from google home.

Using MQTT publisher subscriber for homes with dynamic IP

Getting Started

In order to work with this sample you should register an mqtt account for instance
in https://www.cloudmqtt.com/

The server part is running on your local network
and there is the client part that runs on a machine in the cloud with public endpoint or a static ip

Run the home server

Running the home server on linux\mac

Option 1
  • Run:
    1. $ cd home-server
    2. $ npm install
    3. $ MQTT_URL=mqtts://{{username}}:{{password}}@{{mqtt url}}:{{port}} node server.js
  • Send a request to your client endpoint,

    something like https://{{your endpoint}}/sendCommand?topic=learn&message={deviceName}:{action}

  • See that your broadlink enters learning mode

Option 2
  • Create config.json on the root of your project
    config.json example:

    1. {
    2. "MQTT_URL": "mqtts://{{username}}:{{password}}@{{mqtt url}}:{{port}}"
    3. }
  • Run

  1. $ cd home-server
  2. $ npm install
  3. $ node server.js
  • Send a request to your client endpoint,

    something like https://{{your endpoint}}/sendCommand?topic=learn&message={deviceName}:{action}

  • See that your broadlink enters learning mode

Running the home server on Windows

In order to run on windows you need to:
1) Provide your internal network ip prefix(or your full ip if you prefer)
in a global environment called IP_PREFIX
2) Find your broadcast ip by calling ipconfig as described here
3) Set global environment called BROADCAST_ADDRESS with your broadcast address (or your broadlink address if you prefer)

You can also add a config.json to the root of your project with the above parameters

Option 1
  • run:
    1. $ cd home-server
    2. $ npm install
    3. $ IP_PREFIX=10.0.0 BROADCAST_ADDRESS=10.0.0.255 MQTT_URL=mqtts://{{username}}:{{password}}@{{mqtt url}}:{{port}} node server.js
  • Send a request to your client endpoint,

    something like https://{{your endpoint}}/sendCommand?topic=learn&message={deviceName}:{action}

  • See that your broadlink enters learning mode

Option 2
  • Create config.json on the root of your project
    config.json example:

    1. {
    2. "BROADCAST_ADDRESS": "10.0.0.255",
    3. "MQTT_URL": "mqtts://{{username}}:{{password}}@{{mqtt url}}:{{port}}",
    4. "IP_PREFIX": "10.0.0"
    5. }
  • Run

  1. $ cd home-server
  2. $ npm install
  3. $ node server.js
  • Send a request to your client endpoint,

    something like https://{{your endpoint}}/sendCommand?topic=learn&message={deviceName}:{action}

  • See that your broadlink enters learning mode

Define scenes

Scenes are several commands that runs on a single call

Add the scene name and commands to home-server/scenes-data.json

for example:

  1. {
  2. "switchInput": [{"topic":"tv","action":"input"},{"topic":"tv","action":"input"},{"topic":"tv","action":"ok"}],
  3. "secondScene": [{"topic":"devicename","action":"action"},{}]
  4. }

Acknowledgments