pponce / homebridge-script2

Execute custom scripts via HomeKit apps
89 stars 18 forks source link

State polling interval/manual refresh #34

Open moshed opened 3 years ago

moshed commented 3 years ago

is there a way to manually initiate a state poll or set the interval? Im working on a set of scripts to set the speaker for my Spotify music and the state refreshes reliably every time I close and reopen the home app, but doesn't refresh in any other instance.

pponce commented 3 years ago

I've stopped using this plugin myself so have not fully tested this pull request. Though it seems to have worked for others. https://github.com/pponce/homebridge-script2/pull/15 If you use filestate the plugin should be checking for the existence of the file in order to set homekit state. And it should update homekit right away. So by manipulating the existence of the file you should get immediate updates in homekit. Would this work for you?

moshed commented 3 years ago

it certainly is instant which is great, however im trying to wrap my head around how to carry out my intended workflow.

previously HomeKit would occasionally run my script which checked which speaker was active and turn that on even if I had chosen my speaker outside of HomeKit. currently, HomeKit only checks when I activate the speaker through homekit so if I choose a speaker by any other method nothing trips HomeKit to activate

I know you said you stopped developing this plugin so I dont want to bother you with my rambling, just thinking out loud!

thanks for all your hard work!

pponce commented 3 years ago

Can you run your script external to homebridge to check state and delete/create the filestate file on a schedule, like every 10 seconds? Alternatively: In theory if an external method is used to turn on or off a speaker if that external method also added or deleted the state file i think homekit would then pick up the state change.

moshed commented 3 years ago

hmm that's not a bad idea! I can just run a script on my pi to constantly check for these files... although I have too migrate the Spotify script over to the pi now... hmmm

thanks you've been a big help!

pponce commented 3 years ago

Hope it works. Before doing a bunch of work. Can you try deleting the filestate file manually and adding it back to make sure HomeKit does indeed get pushed the state change. I never tested the PR update that added this check for filestate. So might be worth a check.

moshed commented 3 years ago

I think I did that when I was messing around with it a few nights ago. I will do it again before I do all the work though. smart idea!

moshed commented 3 years ago

it works! great! do you have any plans to work on this in the future would love these to be displayed as a speaker