homebridge-script
homebridge-script copied to clipboard
Give TRUE status for switch back
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
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.
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);
});
}
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.