krvarma / homebridge-particle

Homebridge plugin for Particle Devices
22 stars 14 forks source link

Particle device plugin for Homebridge

As you all know in the new version of Homebridge, the plugin architecture is changed. In new Homebridge, plugins are published through NPM with name starts with homebridge-. Users can install the plugin using NPM.

My previous example of Particle and Homebridge uses old plugin architecture. I have been thinking for a long time to upgrade my previous plugin to the new architecture. But because of many reasons it is delayed. Luckily last week I was able to complete and publish to NPM.

You can install it using NPM like all other modules, you can install using:

npm install -g homebridge-particle.

In this version, I have made some changes from the older version. Mainly the plugin is now a Homebridge Platform. Also in this version accessories are defined in config.json file. The plugin loads the accessories from the config.json file and create accessory dynamically. A sample configuration file is like:

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:39",
        "port": 51826,
        "pin": "031-45-154"
    },

    "description": "This is an example configuration file with one Particle platform and 3 accessories, two lights and a temperature sensor. You should replace the access token and device id placeholder with your access token and device id",

    "platforms": [
        {
            "platform": "Particle",
            "name": "Particle Devices",
            "access_token": "<<access token>>",
            "cloudurl": "https://api.spark.io/v1/devices/",
            "devices": [
                {
                    "accessory": "BedroomLight",
                    "name": "Bedroom Light",
                    "deviceid": "<<device id>>",
                    "type": "LIGHT",
                    "function_name": "onoff",
                    "args": "0={STATE}"
                },
                {
                    "accessory": "KitchenLight",
                    "name": "Kitchen Light",
                    "deviceid": "<<device id>>",
                    "type": "LIGHT",
                    "function_name": "onoff",
                    "args": "1={STATE}"
                },
                {
                    "accessory": "KitchenTemperature",
                    "name": "Kitchen Temperature",
                    "deviceid": "<<device id>>",
                    "type": "SENSOR",
                    "sensorType": "temperature",
                    "key": "temperature",
                    "event_name": "tvalue"
                }
            ]
        }
    ]
}

As you can see from the above example this config.json file defines 3 accessories. 2 Lights and one Temperature Sensor. The access_token defines the Particle Access Token and cloudurl defines the base Particle API url. If you are using the Particle Cloud, then the value of cloudurl should be https://api.spark.io/v1/devices/. If you are using local cloud, then replace with your sensor address.

The devices array contains all the accessories. You can see the accessory object defines following string objects: