homebridge-script icon indicating copy to clipboard operation
homebridge-script copied to clipboard

Give TRUE status for switch back

Open hans-peter123 opened this issue 8 years ago • 3 comments

Hello, what should the state script reply, for a true status in the Home App I tried echo "TRUE"

or something like that, but alway shows the message up:

State of (..) is: false

hans-peter123 avatar Sep 23 '16 22:09 hans-peter123

Same here, I don't quite understand the meaning of the following settings :

      "state": "sh ~/state.sh",
      "fileState": "/Users/olegmalovichko/script.flag",
      "on_value" : "true",
      "exact_match": true

From what I understand of the source, the state is only based on the fileState presence, which is not what I expected. I would think it runs the command state and match the output with on_value, but instead it just checks for file existence and calls back with the file path.

ybizeul avatar Dec 28 '16 15:12 ybizeul

Here is a fix implemented for myself. It completely ignores the fileState, but that works for me.

Edit index.js and replace the following declaration for scriptAccessory.prototype.getState

scriptAccessory.prototype.getState = function(callback) {
  var accessory = this;
  var command = accessory['stateCommand'];
  var stdout = "none";

  exec(command, function (error, stdout, stderr) {
    var cleanOut=stdout.trim().toLowerCase();
    accessory.log('State of ' + accessory.name + ' is: ' + cleanOut);
    callback(null, cleanOut == accessory.onValue);
  });
}

ybizeul avatar Dec 28 '16 16:12 ybizeul

I added your code to my fork. Can choose to use filestate if you configure filestate. Otherwise uses state script. Also works with the latest file-exists and added it as a dependency so should not need to install it separately.

pponce avatar Mar 12 '17 07:03 pponce