So I have set up my command line switch with command on and off specified. I also have the state command which gives me the state if I was to run it in terminal.
However when I insert the command state, it shows my switch as on whilst its off and it wouldnt turn off. I have also set the value template to 1, as what other HA users have done but no jouy
I ended up having to write a bash file and then call this file from the command_line component. That way, I could pass the value back. Mine was being sent back as something that wasn’t exiting properly. So in my bash file I would review the result and then perform an exit 0 or 1 depending on the result. This allowed HA to handle it directly vs. having to use a value template.
Sorry, I guess mine was in javascript and not a bash file, but I believe the concept would be the same thing (obviously different language). With a bash you’d want to determine your exit code based on the response from your command. This code calls a function within a nodejs module. The output of that function was in an array, so before returning the value I converted the array to a string as it returns the status of my lights in binary (it’s an old lighting program). This code sifts through the binary based on my original input parameters to return the status of the light in question. Then, based on the return value I exit with a 0 or a 1. That exit is handled by HA to display the status of the light. The exit code should be 0 for on or 1 (or other value) for off.
I’m not a programmer, but once I figured out the exit state it works flawlessly. I’m running hassbian and don’t know anything about docker so I can’t help you if it’s a docker issue.
var keypad = process.argv[2];
var button = process.argv[3];
var LiteTouch = require('litetouch');
var litetouch = LiteTouch.connect('192.xxx.x.xxx', xxxx1, function() {
});
litetouch.getLEDStates(keypad,function(err,callback) {
var ledstatus = callback.substr(callback.length - button);
var ledStateFinal = ledstatus.substr(0,1);
if (err) {
console.log("ERROR ", err);
return;
}
else if (callback.length == 1 && callback.length < button) {
console.log(-1);
process.exit(-1);
}
else if (callback.length < button) {
console.log(-1);
process.exit(-1);
}
// Light is on
else if (ledStateFinal == 1) {
console.log(0);
process.exit(0);
}
else
console.log(-1);
process.exit(-1);
});
Hello. I know this is an old post, but thought I would share what I did to get this to work properly. In the value template, replace “value” with what is actually being reported with the call. In this case, the full result is “display_power=1” when on. So the YAML looks like this.
Hello. I am trying to configure the state and the icon of the below switch.
the on and off work well but for the rest I definetly havent done it correct!
any suggestion?