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

A little help here - device always off... #59

Closed BKeyport closed 4 years ago

BKeyport commented 4 years ago

I'm having some difficulty here.

I'm using a tutorial that's out of date for Homebridge to control my Pi's monitor. I want it off when I'm not present, and on when I am, with the state of the rest of my smart home.

I've modified the suggested config, as tvservice doesn't control my HDMI port correctly. My modifications work, however, I have no idea how to fix the "state_cmd", and it's always off.

If I run tvservice on the command line as listed in the config, it returns nothing.

If I run it without the grep, it returns: state 0xa [HDMI CUSTOM RGB lim 16:9], 1920x1080 @ 60.00Hz, progressive

As I'm using vcgencmd, is there a way I can use that instead? If I enter vcgencmd display_power it'll return "display_power=1" if on, "display_power 0" if off.

Thanks!

Here's the original config:

"platforms": [{
  "platform": "cmdSwitch2",
  "name": "Raspberry Pi",
  "switches": [{
    "name" : "Mirror",
    "on_cmd": "tvservice --preferred && sudo chvt 6 && sudo chvt 7",
    "off_cmd": "tvservice -o",
    "state_cmd": "tvservice --status | grep -i 'HDMI DMT'",
    "manufacturer": "Raspberry Pi Foundation",
    "model": "Raspberry Pi 3 Model B",
  }]
}]

Here's the config as I have it as present:

 {
            "platform": "cmdSwitch2",
            "name": "Raspberry Pi",
            "switches": [
                {
                    "name": "Mirror",
                    "on_cmd": "vcgencmd display_power 1",
                    "off_cmd": "vcgencmd display_power 0",
                    "state_cmd": "tvservice --status | grep -i 'HDMI DMT'",
                     "manufacturer": "Raspberry Pi Foundation",
                    "model": "Raspberry Pi 3 Model B"
                }
            ]
        }
    ]
}
BKeyport commented 4 years ago

I happened to mention this on twitter, and they gave me the proper command.

If you're wondering...

"state_cmd": "vcgencmd display_power | grep -i 'display_power=1'",