rudders / homebridge-http

HTTP Plugin for Homebridge
Apache License 2.0
178 stars 110 forks source link

Push Button #56

Closed RickNunn closed 7 years ago

RickNunn commented 7 years ago

Is it possible to have a button that reverts back to it's off state after activation?

I've just got this running with https://github.com/jishi/node-sonos-http-api and I've got some presets which I switch "on" with a http request. But after the http request has completed I'd the button to revert back to it's off state (without sending an additional command).

Is that possible currently?

NovaGL commented 7 years ago

Not currently. Open to suggestions. Could be another button type.

NovaGL commented 7 years ago

Although I am against adding additional services to this repo I might make an exception for this one.

It appears Homebridge does do stateless commands

All we have to do is create another button type and integrate it in. So then there will be the choice between. Switch, Light or stateless.

Service.StatelessProgrammableSwitch = function(displayName, subtype) {
  Service.call(this, displayName, '00000089-0000-1000-8000-0026BB765291', subtype);

  // Required Characteristics
  this.addCharacteristic(Characteristic.ProgrammableSwitchEvent);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.Name);
};

inherits(Service.StatelessProgrammableSwitch, Service);

Service.StatelessProgrammableSwitch.UUID = '00000089-0000-1000-8000-0026BB765291';
RickNunn commented 7 years ago

Oh man that would be awesome! You'd have my eternal gratitude and I'll buy you a coffee some time!

NovaGL commented 7 years ago

Sadly it doesn't look like that is the way stateless switches work.

It seems they are intended to work with devices outside homebridge eg a physical button.

No UI button appears when you try to do a stateless button.

Have you considered just doing the off command as pause? That is what I do.

NovaGL commented 7 years ago

I think the best thing we can do is use a timer, not sure how to do it though

  if (on) {
    setTimeout(function() {
      this._service.setCharacteristic(Characteristic.On, false);
    }.bind(this), 1000);
  }
RickNunn commented 7 years ago

After doing a bit looking around I've seen that IFTTT buttons behave in a push button way — https://github.com/ilcato/homebridge-ifttt

Does that shine any light on the situation?

If you specify both "triggerOn" and "triggerOff" values to a button configuration it will generate different triggers for the two different status of the switch.

If you only specify the "trigger" value to a button configuration it will behave like a push button generating the trigger after the selection of the button and automatically returning to the off status.

NovaGL commented 7 years ago

Hi @RickNunn

I have tested this repo - https://github.com/lucacri/homebridge-http-simple-switch\

And it works as desired. Feel free to do a pull request if you can figure out how to integrate it into this repo. I feel its to different though