Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert the sensor state when calendar invent starts #27

Open
AdeTheux opened this issue Nov 3, 2020 · 2 comments
Open

Invert the sensor state when calendar invent starts #27

AdeTheux opened this issue Nov 3, 2020 · 2 comments

Comments

@AdeTheux
Copy link

AdeTheux commented Nov 3, 2020

Is there any way to invert the way the sensor is displayed in the Home app? Currently, if there's a calendar event happening at a specific time (no offset configured), the sensor state will appear as "opened". I'd like it to be "closed", as in the office is closed because a meeting is starting.
Thanks

@CHuOK68
Copy link

CHuOK68 commented Aug 20, 2021

Good idea

@AdeTheux
Copy link
Author

I've managed to do this.
Go to /usr/lib/node_modules/homebridge-calendar/src
Open calendarsensor.js and compare the changes in the code below, I don't remember precisely what I changed a while back…
But it now displays the open sensor/door in homebridge for my office when I don't have anything in my work diary.


'use strict';

class CalendarSensor {

  constructor(log, name, sensor, characteristic, onValue, offValue) {
    this.log = log;
    this.name = name;
    this.sensor = sensor;
    this._characteristic = characteristic;
    this._onValue = onValue;
    this._offValue = offValue;

    this.reset();
    this.pushState();
  }

  reset() {
    this._state = 1;
  }

  off() {
    this._state++;
  }

  on() {
    if (this._state > 0) {
      this._state--;
    }
  }

  pushState() {
    let value = this._offValue;
    if (this._state > 0) {
      value = this._onValue;
    }

    this.log(`Pushing calendar sensor '${this.name}' state ${this._state} - value ${value}`);
    this.sensor
      .getCharacteristic(this._characteristic)
      .updateValue(value);
  }
}

module.exports = CalendarSensor;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants