homebridge-calendar
homebridge-calendar copied to clipboard
Invert the sensor state when calendar invent starts
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
Good idea
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;