pponce/homebridge-script2

Is it possible to set state of script2 device programmatically?

Closed this issue · 3 comments

I have two script2 devices representing the inputs to an amplifier: "cable" and "tv". When one is on, the other should be off and vice-versa.

I can use HomeKit automations to achieve this [e.g. when "cable" switches on, switch off "tv"], but is there a way that I can do it by including a command in the script2 scripts?

The short answer is, “kind of”. The scripts you create to turn on each input can be made to turn on the intended input and turn off the other input. It can also create the appropriate filestate file for the input being turned on and remove the filestate file for the input you want turned off. Assuming you are using filestate files.
But HomeKit won’t know about the changes until HomeKit checks for file state again. I know that exiting and re-entering the home app triggers this check. Not perfect but would work.
Some sort of polling function could be probably be added to update state periodically but I don’t have the time right now to work on this. Feel free to make some changes if you want to submit a pr.

You could check out https://www.npmjs.com/package/homebridge-cmdswitch2
It already has polling built in to check state.

I know this is an old issue.
But i wanted to point out that this PR may solve for this request/issue.
#15

I've not tested it. But in theory with this PR if you use fileState files to determine on off state then you can write a script that removes the file for one device when you add a file for a different device.
The update should control on off states by monitoring the fileState files and update homekit accordingly.