particleio-homekit icon indicating copy to clipboard operation
particleio-homekit copied to clipboard

Updated code

Open pedroserano opened this issue 9 years ago • 7 comments

This code updates particleio-homekit to work with the latest version of homebridge and particle.io.

Thank you for all your really hard work creating this!

pedroserano avatar Dec 10 '15 04:12 pedroserano

Thank you so much! It will take for me some time to setup a test stage again, but code wise everything looks excellent. I just need to check that it works :) Thanks again!

nikita-leonov avatar Dec 10 '15 05:12 nikita-leonov

Of course it's the least I can do. I don't know whether it has to be installed in the accessories folder of the homebridge-legacy-plugins, but I did so on mine to be safe and it works.

pedroserano avatar Dec 10 '15 13:12 pedroserano

@pedroserano I'm trying out your version, but I'm running into a problem. This is what I'm running:

$ npm install -g https://github.com/pedroserano/hombridge-particle

The installation runs successfully. But when I run homebridge, I got an error:

$ homebridge
====================
ERROR LOADING PLUGIN homebridge-particle:
Error: Cannot find module 'node_modules/hap-nodejs/accessories/types.js'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge-particle/index.js:2:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
====================
No plugins found. See the README for information on installing plugins.
Loaded config.json with 1 accessories and 0 platforms.
---
Loading 1 accessories...
/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/api.js:47
      throw new Error("The requested accessory '" + name + "' was not registered by any plugin.");
      ^

Error: The requested accessory 'homebridge-particle' was not registered by any plugin.
    at API.accessory (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/api.js:47:13)
    at Server._loadAccessories (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:164:42)
    at Server.run (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:36:38)
    at module.exports (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/cli.js:23:16)
    at Object.<anonymous> (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

I solve that by replacing var types = require("node_modules/hap-nodejs/accessories/types.js"); with var types = require("HAP-NodeJS/accessories/types.js");

But then I run into another error:

$ homebridge
Loaded plugin: homebridge-particle
Registering accessory 'homebridge-particle.Particle'
---
Loaded config.json with 1 accessories and 0 platforms.
---
Loading 1 accessories...
/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/api.js:47
      throw new Error("The requested accessory '" + name + "' was not registered by any plugin.");
      ^

Error: The requested accessory 'homebridge-particle' was not registered by any plugin.
    at API.accessory (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/api.js:47:13)
    at Server._loadAccessories (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:164:42)
    at Server.run (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:36:38)
    at module.exports (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/cli.js:23:16)
    at Object.<anonymous> (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

This is what my config file look like:

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

    "description": "Copy and paste of the config-sample.js",

     "accessories": [
        {
        "accessory": "homebridge-particle",
        "name": "Particle Sensor",
        "platform_url": "https://api.particle.io/v1",
        "device_id": "53ff69066678505521262467",
        "access_token": "44834d2eb7e2837fec72b8272df66acc95f44386"
        }
    ]

}

I see that the information on your README is different then your config.json, so I try to update my config file to:

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

    "description": "Copy and paste of the config-sample.js",

    "accessories": [
        {
            "accessory": "Particle",  // < Updated line
            "name": "Particle Sensor",
            "platform_url": "https://api.particle.io/v1",
            "device_id": "53ff69063678505521262467",
            "access_token": "44864d2eb7e2837fec72b8272df66acc95f44386"
        }
    ]

}

But the error continues the same. Except now there is a new line that says:

Registering accessory 'homebridge-particle.Particle'

So I update the config file accordingly:

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

    "description": "Copy and paste of the config-sample.js",

    "accessories": [
        {
            "accessory": "homebridge-particle.Particle",  // < Updated line
            "name": "Particle Sensor",
            "platform_url": "https://api.particle.io/v1",
            "device_id": "53ff69063678505521262467",
            "access_token": "44864d2eb7e2837fec72b8272df66acc95f44386"
        }
    ]

}

The error changes, which is great! Now the output is:

$ homebridge
Loaded plugin: homebridge-particle
Registering accessory 'homebridge-particle.Particle'
---
Loaded config.json with 1 accessories and 0 platforms.
---
Loading 1 accessories...
[Particle Sensor] Initializing homebridge-particle.Particle accessory...
/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge-particle/index.js:65
      sType: types.ACCESSORY_INFORMATION_STYPE,
                  ^

TypeError: Cannot read property 'ACCESSORY_INFORMATION_STYPE' of undefined
    at Object.ParticleAccessory.getServices (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge-particle/index.js:65:19)
    at Server._createAccessory (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:235:36)
    at Server._loadAccessories (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:176:26)
    at Server.run (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/server.js:36:38)
    at module.exports (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/lib/cli.js:23:16)
    at Object.<anonymous> (/Users/myuser/.nvm/versions/v4.1.2/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

Problem now: It seems the types variable is not accessible inside getServices. But I had to change the require to get it working, so that might be related.

felippenardi avatar Jan 04 '16 02:01 felippenardi

It seems that on line 10 (types = homebridge.hap.Types;) the types value is being overwritten, so all its properties are not accessible inside getServices.

I created a another variable (var types2 = require("HAP-NodeJS/accessories/types.js");) and replaced types with types2 in all lines below line 26.

Result:

$ homebridge
Loaded plugin: homebridge-particle
Registering accessory 'homebridge-particle.Particle'
---
Loaded config.json with 1 accessories and 0 platforms.
---
Loading 1 accessories...
[Particle Sensor] Initializing homebridge-particle.Particle accessory...
Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

    ┌────────────┐
    │ 763-11-873 │
    └────────────┘

Homebridge is running on port 51826.

Which means YAY.

I'm now going to test it on the particle itself.

felippenardi avatar Jan 04 '16 02:01 felippenardi

@felippenardi thanks for this effort. I am still in a holiday haste now, so was not able to rebuild my testing rig and check PR yet. Let me know if you will get it working with a suggested changes. Thanks again!

nikita-leonov avatar Jan 07 '16 07:01 nikita-leonov

@felippenardi I've just seen this having wondered for a while what the plugin version of this would look like. Did you get it working? It looks like your .ino file is still missing some parts of the HSL conversion. See my PR which adds the correct/working version.

JoniSykes avatar Jan 06 '17 13:01 JoniSykes

I've managed to get this (sort of) working. Powerstate is working fine, but Hue, Brightness and Saturation are not functioning properly. If I select a brightness it seems to change the colour. Selecting the colour seems to do nothing. Any ideas?

JoniSykes avatar Jan 06 '17 14:01 JoniSykes