pponce/homebridge-script2

Events fire twice with fileState configured

max-christian opened this issue · 7 comments

The new functionality to send on/off messages to HomeKit when the fileState parameter is configured seems to be working well except that events sometimes fire twice, e.g.

  1. Message comes from HomeKit to switch on
  2. On script is invoked and creates a file at fileState
  3. script2 sees the file get created and invokes the on script a second time

Maybe the sinplest resolution is that step 3 should only happen if the creation/deletion of the file changes the state to the opposite of the current state?

can you test this version for me
npm install -g git+https://github.com/pponce/homebridge-script2

Okay, giving that version a go now. I also have an attempted fix: https://github.com/max-christian/homebridge-script2/blob/master/index.js

I'm still seeing a duplicate call with that version (my switch is called "Max at home"):

[12/20/2018, 6:11:05 PM] [Max at home] Set Max at home to off
[12/20/2018, 6:11:05 PM] [Max at home] File /Users/admin/x10/home-status-max was deleted
[12/20/2018, 6:11:05 PM] [Max at home] Set Max at home to off
——
[12/20/2018, 6:11:07 PM] [Max at home] Set Max at home to on
[12/20/2018, 6:11:07 PM] [Max at home] File /Users/admin/x10/home-status-max was created
[12/20/2018, 6:11:07 PM] [Max at home] Set Max at home to on
——
[12/20/2018, 6:11:13 PM] [Max at home] Set Max at home to off
[12/20/2018, 6:11:13 PM] [Max at home] File /Users/admin/x10/home-status-max was deleted
[12/20/2018, 6:11:13 PM] [Max at home] Set Max at home to off

ok can you try installing from git again?
just put in your fix. I can't test right now as i'm at work...

I download as a .zip from github, did an "npm install" and ran homebridge with -P:

homebridge -P ~/homebridge-script2-master/

Seems to work well:

[12/20/2018, 7:56:35 PM] [Max at home] State of Max at home is: false
[12/20/2018, 7:57:10 PM] [Max at home] State of Max at home is: false
[12/20/2018, 7:57:12 PM] [Max at home] Set Max at home to on
[12/20/2018, 7:57:16 PM] [Max at home] Set Max at home to off
——
[12/20/2018, 7:57:42 PM] [Max at home] File /Users/admin/x10/home-status-max was created
[12/20/2018, 7:57:42 PM] [Max at home] Set Max at home to on
——
[12/20/2018, 7:57:53 PM] [Max at home] File /Users/admin/x10/home-status-max was deleted
[12/20/2018, 7:57:53 PM] [Max at home] Set Max at home to off
——
[12/20/2018, 7:57:58 PM] [Max at home] File /Users/admin/x10/home-status-max was created
[12/20/2018, 7:57:58 PM] [Max at home] Set Max at home to on
——
[12/20/2018, 7:58:08 PM] [Max at home] Set Max at home to off
[12/20/2018, 7:58:11 PM] [Max at home] Set Max at home to on

thank! i'll push it through today as a fix.

just published with your changes.