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

Always on

Open berkaytheunicorn opened this issue 7 years ago • 2 comments

Hey there, I have simple set up


"switches" : [
        {
          "state_cmd" : "gpio read 4", // returns 1 or 0 also try to create a bash script to return true or false
          "name" : "Lamp",
          "on_cmd" : "gpio write 4 1",
          "off_cmd" : "gpio write 4 0",
	  "pooling": true
        }
]

with bash


"switches" : [
        {
          "state_cmd" : "/home/pi/read.sh",
          "name" : "Lamp",
          "on_cmd" : "gpio write 4 1",
          "off_cmd" : "gpio write 4 0",
	  "pooling": true
        }
]

bash

#!/bin/sh

# GPIO setup:
# Pin 4 (GPIO0): switch 

if [ "`gpio read 4`" -eq 1 ]; then
	echo true
fi;


if [ "`gpio read 4`" -eq 0 ]; then
	echo false
fi;

on off works great but after I off the lamp 1-2 secons later it just became on in state but not really.

am i doing something wrong here?

berkaytheunicorn avatar May 23 '17 11:05 berkaytheunicorn

The state checking algorithm is basically checking if the state command returns an empty string. You can try gpio read 4 | grep -i "true" something like that.

luisiam avatar Jun 30 '17 00:06 luisiam

Try this:

"switches" : [
        {
          "state_cmd" : "sh /home/pi/read.sh",
          "name" : "Lamp",
          "on_cmd" : "gpio write 4 1",
          "off_cmd" : "gpio write 4 0",
	  "pooling": true
        }
]

read.sh

gpioread = $(gpio read 4)
if [ $gpioread -eq 1 ]
then
exit 0
fi


if [ $gpioread -eq 0 ]
then
exit 1
fi

HomeKit need a Exit-Code 0 for device ON and all other Exit-Codes = OFF. "gpio read" gives a "1" or a "0". But dont gives a Error-Code "1" or "0". "gpio read" gives always Error-Code 0, and that is the code for ON.

theend92 avatar Mar 11 '18 05:03 theend92