Relay

UUID: 0000005A-0000-1000-8000-0026BB765291

Required Characteristics

Example

Note

The example below is automatically generated and may not be a complete example of what is required to create a working "Relay" Homebridge plugin.
// Example Relay Plugin

module.exports = (api) => {
  api.registerAccessory('ExampleRelayPlugin', ExampleRelayAccessory);
};

class ExampleRelayAccessory {

  constructor(log, config, api) {
      this.log = log;
      this.config = config;
      this.api = api;

      this.Service = this.api.hap.Service;
      this.Characteristic = this.api.hap.Characteristic;

      // extract name from config
      this.name = config.name;

      // create a new Relay service
      this.service = new this.Service(this.Service.Relay);

      // create handlers for required characteristics
      this.service.getCharacteristic(this.Characteristic.RelayEnabled)
        .on('get', this.handleRelayEnabledGet.bind(this))
        .on('set', this.handleRelayEnabledSet.bind(this));

      this.service.getCharacteristic(this.Characteristic.RelayState)
        .on('get', this.handleRelayStateGet.bind(this));

  }

  /**
   * Handle requests to get the current value of the "Relay Enabled" characteristic
   */
  handleRelayEnabledGet(callback) {
    this.log.debug('Triggered GET RelayEnabled');

    // set this to a valid value for RelayEnabled
    const currentValue = 1;

    callback(null, currentValue);
  }

  /**
   * Handle requests to set the "Relay Enabled" characteristic
   */
  handleRelayEnabledSet(value, callback) {
    this.log.debug('Triggered SET RelayEnabled:' value);

    callback(null);
  }

  /**
   * Handle requests to get the current value of the "Relay State" characteristic
   */
  handleRelayStateGet(callback) {
    this.log.debug('Triggered GET RelayState');

    // set this to a valid value for RelayState
    const currentValue = 1;

    callback(null, currentValue);
  }


}