paulw11 / homebridge-elkm1

Homebridge plugin for the Elk M1 alarm panel
MIT License
7 stars 6 forks source link

Outputs Turning Off Uncommanded(?) #26

Closed subcritical71 closed 3 years ago

subcritical71 commented 3 years ago

First, great product, I have been using it effortlessly for a few months now.

I recently installed a plugin (Smart Irrigation) to better automate my sprinklers. Now I am trying to narrow down an issue I am having with my automations. I am using Homebridge UI (4.41.1), ElkM1 (v3.0.3), and SmartIrrigation (v1.5.1). The SmartIrrigation - [https://github.com/MTry/homebridge-smart-irrigation#readme] creates dummy zones for later control of the irrigation system. I have successfully mapped and can control these dummy zones to the real ELK outputs using Scenes/Rules in the Eve App. I can successfully turn the outputs on and off. The issue comes along when a few minutes into the watering cycle the output turns off. I've looked at the ELKM1 (RP2) log files - No help, and the homebridge log files and can only see the result, not what is taking the action of turning off the output. Is there anything in your code which would trigger an output to turn off?

Using the EKeypad app on an iphone I can turn the output on and it stays on until I turn it off so its not any Elk control panel rules that are shutting it off. The Eve app appears to be operating correctly also. There is a countdown which is still counting when the output turns off, the dummy zones still show ON. Also, turning on the actual ELK irrigation output in Homekit does not result in this turn off behavior either.

Here is what homebridge reports when it occurs (output in this case is ID: 35);

[5/17/2021, 12:41:59 PM] [ElkM1] Setting output 35 to true  newState = true currentState = false
[5/17/2021, 12:41:59 PM] [ElkM1] OutputChangeUpdate {
  message: '0ACC035100E0',
  body: '035100',
  type: 'CC',
  hexLength: '0A',
  checkSum: 'E0',
  id: 35,
  state: 'On'
}
[5/17/2021, 12:42:09 PM] [ElkM1] ElkMessage {
  message: '16XK02421221705211100077',
  body: '024212217052111000',
  type: 'XK',
  hexLength: '16',
  checkSum: '77'
}
[5/17/2021, 12:42:18 PM] [ElkM1] ElkMessage {
  message: '0CST013130005E',
  body: '01313000',
  type: 'ST',
  hexLength: '0C',
  checkSum: '5E'
}
[5/17/2021, 12:42:39 PM] [ElkM1] ElkMessage {
  message: '16XK32421221705211100074',
  body: '324212217052111000',
  type: 'XK',
  hexLength: '16',
  checkSum: '74'
}
[5/17/2021, 12:42:50 PM] [ElkM1] ElkMessage {
  message: '0CST0131290056',
  body: '01312900',
  type: 'ST',
  hexLength: '0C',
  checkSum: '56'
}
[5/17/2021, 12:43:09 PM] [ElkM1] ElkMessage {
  message: '16XK02431221705211100076',
  body: '024312217052111000',
  type: 'XK',
  hexLength: '16',
  checkSum: '76'
}
[5/17/2021, 12:43:35 PM] [ElkM1] OutputChangeUpdate {
  message: '0ACC035000E1',
  body: '035000',
  type: 'CC',
  hexLength: '0A',
  checkSum: 'E1',
  id: 35,
  state: 'Off'
}
[5/17/2021, 12:43:39 PM] [ElkM1] ElkMessage {
  message: '16XK32431221705211100073',
  body: '324312217052111000',
  type: 'XK',
  hexLength: '16',
  checkSum: '73'
}

Thanks!

paulw11 commented 3 years ago

The log shows that a CC status was received from the panel with output 35 in an "off" state. If homebridge-elkm1 had turned the output off you would see the line "setting output 35 ...." as you do at the start of the log.

subcritical71 commented 3 years ago

Ok, thank you. I will close as the plugin does not appear to be the source of the off command. Thanks again.

subcritical71 commented 3 years ago

I was looking though the Elk RS232-ASCII reference. In the section to turn on the Control Output Change (to On) there is a time setting.

4.8.2 Control Output On (cn) 0EcnDDDTTTTT00CC(CR-LF) Example: turn on Control Output 1 for 10 seconds: 0Ecn0010001000D8(CR-LF )

What is the plugin setting the TTTTT to? Is it able to accept input from Homekit (actually the Eve App) to populate this value? Below is the scene I created in the Eve App for, in this case, zone 3 of the irrigation system. IMG_0477

subcritical71 commented 3 years ago

Ok, just had a look at elkmon, it seems it does allow to message the M1 with a time;

https://github.com/sgentry/elkmon/blob/7da5cc0f30088bc80683d6fe3689fffa9fc52940/src/index.ts#L165-L174

/**
   * Turn output on.
   * 
   * @param {number} outputId
   * @param {number} seconds - Number of seconds output will be active
   */
  setOutputOn(outputId: number, seconds: number) {
    let elk = new ElkMessage(`cn${leftPad(outputId.toString(), 3, '0')}${seconds.toString()}`, null);
    this.connection.write(`${elk.message}\r\n`);
  }

but the elkm1 plugin is passing a 0 value, which I think is good enough;

https://github.com/paulw11/homebridge-elkm1/blob/bc6534d2c58c6a87f38cf739c9e90394bd6566ed/src/accessories/ElkOutput.ts#L67-L79

    async setOutput(value: CharacteristicValue) {
        const newState = `${value}` === 'true';
        this.platform.log.debug(`Setting output ${this.id} to ${value}  newState = ${newState} currentState = ${this.isOn}`);
        if (newState !== this.isOn) {
            if (newState) {
                this.elk.setOutputOn(this.id, 0);
            } else {
                this.elk.setOutputOff(this.id);
            }
            this.isOn = newState;
        }
    }

I'm not much of a programmer, so I don't understand how elkmon is padding the 5 T's to create a proper message format similar to what it did for the output number with the left pad.

paulw11 commented 3 years ago

The elkmon code does look like it isn't creating the message properly. I only use an output for pulsing my garage door relay. It may be that the m1 handles the non-padded duration correctly or it could be the source of your problem.

I will do some testing when I get home and submit a PR to elkmon if is a bug

subcritical71 commented 3 years ago

That appears to be the issue. I changed the code in elkmon to '00000' and reran my automation. It worked as expected. It would be nice if your plugin could transfer the actual timer value to elkmon. The way I have it now homekit will send an off command when the timer expires. But if the m1 already knows when this off will be it will serve as a backup so I don't leave my sprinklers on for hours in case something hangs. :)

paulw11 commented 3 years ago

Unfortunately the timer isn’t part of the HomeKit accessory. HomeKit simply turns outputs “on” or “off”. The timer part is logic in the smart irrigation plugin.

I will create a PR for elkmon to fix the message format bug

paulw11 commented 3 years ago

I have raised an issue - https://github.com/sgentry/elkmon/issues/7 and submitted a PR to elkmon to address it

paulw11 commented 3 years ago

The elkmon pr has been accepted. Once the new version of elkmon is released this should be resolved.

subcritical71 commented 3 years ago

Great, thanks for the support. I'll close this issue.

subcritical71 commented 3 years ago

Paul, could you increment the version of your plugin with the latest elkmon dependency? For some reason last night my elkmon reverted back to turning on the output without the proper padding.

paulw11 commented 3 years ago

3.0.4 updates the dependency

subcritical71 commented 3 years ago

@paulw11 Did you mean to remove the dependency to elkmon? Your plug-in will not load now complaining about elkmon being missing.

paulw11 commented 3 years ago

Not sure what I did there. 3.0.5 is now available

paulw11 commented 3 years ago

This is still a problem because elkmon 1.2.4 doesn't actually include the fix. See https://github.com/sgentry/elkmon/issues/10 As a work around you can manually make a change to index.js in the elkmon directory under /usr/lib/node_modules/homebridge-elkm1/node_modules/elkmon/dist

 let elk = new messages_1.ElkMessage(`cn${utils_1.leftPad(outputId.toString(), 3, '0')}${utils_1.leftPad(seconds.toString(),5,'0')}`, null);
paulw11 commented 3 years ago

Elkmon 1.2.5 fixes this