luisiam / homebridge-cmdswitch2

CMD Plugin for HomeBridge (API 2.0): https://github.com/nfarina/homebridge
Apache License 2.0
176 stars 29 forks source link

state_cmd #24

Open jkomaha opened 7 years ago

jkomaha commented 7 years ago

Having an issue with the state_cmd - everything is returned as state ON with the following configuration. pgrep returns the PID if the process is found, or nothing if not.

{"name": "Dim Red",
     "on_cmd" : "~/.homebridge/dim_red",
     "off_cmd" : "~/.homebridge/leds_off",
     "state_cmd" : "ps aux | pgrep -f dim_red"
    },
    {"name": "Bright Red",
     "on_cmd" : "~/.homebridge/bright_red",
     "off_cmd" : "~/.homebridge/leds_off",
     "state_cmd" : "ps aux | pgrep -f bright_red"
    },
    {"name": "Dim Blue",
     "on_cmd" : "~/.homebridge/dim_blue",
     "off_cmd" : "~/.homebridge/leds_off",
     "state_cmd" : "ps aux | pgrep -f dim_blue"
    },
    {"name" : "Bright Blue",
     "on_cmd" : "~/.homebridge/bright_blue",
     "off_cmd" : "~/.homebridge/leds_off",
     "state_cmd" : "ps aux | pgrep -f bright_blue"
    }
theend92 commented 6 years ago

Try this: "state_cmd": "if pgrep -i 'dim_red'; then exit 0; fi; exit 1"