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

Ability to run script in background or set customizable timeout #13

Closed nriley closed 7 years ago

nriley commented 7 years ago

One of the things I expose via homebridge is my desktop Mac's screen, and the only easy way I'm aware to script waking it up is by setting a power assertion with a 1 second timeout — which means the process takes at least one second to run. I tried many many ways to run this in the background (e.g. using &, or disown, etc.) but all of them run into the cmdswitch2 timeout. I did eventually make it work by putting caffeinate into a launchd job, so if anyone else sees this, my switch looks like this:

                {
                    "name": "Mary screen",
                    "on_cmd": "/bin/launchctl kickstart gui/$UID/net.sabi.WakeScreen",
                    "off_cmd": "/usr/bin/pmset displaysleepnow"
                },

where the launchd plist looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>net.sabi.WakeScreen</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/caffeinate</string>
        <string>-u</string>
        <string>-t</string>
        <string>1</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
</dict>
</plist>

but this took quite a while to figure out. Either a way to set the timeout to something longer than 1 second, or a way to just let the script run in the background would be appreciated.

Thanks!

luisiam commented 7 years ago

The script should just run in the background. That 1 second timeout is just for giving response back to Siri. If you are using Siri and it doesn't get any response back in 1 or 2 seconds, Siri will think that the device is not responding.

fafoulon commented 7 years ago

I manually changed it in the index.js to 4000, and Siri has no problem with that. It's the same delay for some other homebridge platforms I have, and Siri is always happy with delays.

neptunix commented 7 years ago

Hi!

I've implemented custom timeouts in this pull request: https://github.com/luisiam/homebridge-cmdswitch2/pull/17

luisiam commented 7 years ago

Pull request merged