homebridge / HAP-NodeJS

Node.js implementation of the HomeKit Accessory Protocol (HAP)
Apache License 2.0
2.68k stars 630 forks source link

Control Milight #81

Closed hans-peter123 closed 9 years ago

hans-peter123 commented 9 years ago

Hello, I search after a accessory.js file, who execute own bash commands!? Does anyone have a solution? I want to control my milight controller. With bash, for example, this works how follow: "/home/pi/milight_sources/./milight 1 b 19" Thanks for helping

snowdd1 commented 9 years ago

That's not a HAP but a nodeJS question. Dr. Google shows up with http://www.dzone.com/snippets/execute-unix-command-nodejs for example.

hans-peter123 commented 9 years ago

Oh, thanks for that. Now it works with: "/home/pi/milight_sources/./milight OFF" But when I hit On (in the MyTouchHome app), by both positions the OFF command is send. How van I use the value variable to control this?

hans-peter123 commented 9 years ago

By the way, I use this code:

cType: types.POWER_STATE_CTYPE,
    onUpdate: function(value) {
         var cmd = "/home/pi/milight_sources/./milight OFF"

         exec(cmd, function(error, stdout, stderr) {
            // command output is in stdout
         });
    },

Here is the OFF command hardcoded...

I also tried this:

var cmd = "/home/pi/milight_sources/./milight " + value;

But it doesn't work :(

snowdd1 commented 9 years ago

what about:

var cmd = "/home/pi/milight_sources/./milight";
var cmdOn = cmd + " ON";
var cmdOff = cmd + " OFF";
if (value) {
  // now we now it's "true-ish" (True, >0, a string not empty, whatever javascript likes as true)
          exec(cmdOn, function(error, stdout, stderr) {
            // command output is in stdout
         });
} else {
  // now we now it's "false-ish" (undefined, false, 0, an empty string ... etc)
          exec(cmdOff, function(error, stdout, stderr) {
            // command output is in stdout
         });
};

But really: have a look at javascript documentation, otherwise you are going to have a really hard time configuring your devices!

hans-peter123 commented 9 years ago

Woh, thanks for that. It works!! :)