simont77 / fakegato-history

Module to emulate Elgato Eve history
MIT License
168 stars 16 forks source link

Getting "Last Activation" to show value?? #87

Closed n0rt0nthec4t closed 4 years ago

n0rt0nthec4t commented 4 years ago

I have history recording against my garage door accessory and have callbacks setup to set both the "Times Opened" and "Last Entry" (11A) Eve characteristics. Can successfully set Times Open to match, but unable to get any time/value shown for the "last Entry" field

Any know the "magic sauce" to get a valve populated Into this field? I have tried "LastEntry".time - initialTime, currentime - "LastEntry".time etc

simont77 commented 4 years ago

As explained in the readme the Value for last entry is the number of second from reset of fakegato-history. You can get this time using the function getInitialTime(). In my accessories I have simply this.lastActivation = moment().unix() - this.LoggingService.getInitialTime(). However Eve may restrict the proper operation of this characteristics to Accessory that emulates properly Door or Motion, with all the extra characteristics in place.

n0rt0nthec4t commented 4 years ago

Ok, so this is what I have observed. using this.lastActivation = moment().unix() - this.LoggingService.getInitialTime(). and perform a pulldown refresh in the Eve app always reverts to "just now". Changing this to this.lastActivation = moment().unix() - this.LoggingService.getInitialTime() - ("time since last event in seconds" seems to make Eve ap report correctly

So atleast in the current Eve app, lastActivation is number of seconds since the first event to the last event

simont77 commented 4 years ago

Could you share your code and Homebridge version? I’m using the latest Eve.app and homebridge 0.4.53 and I can confirm that nothing changed, last activation still works in my plugin as it has done in the last two years.

simont77 commented 4 years ago

I went through the fakegato code (it was a long time since I've written it) and InitialTime is automatically set equal to the first event when the first event is added to the history. Are you using history persistance? Could you check in debug the value of initialTime? Also, check that the clock of your homebridge server and iOS device are synchronized and on the same time zone.

n0rt0nthec4t commented 4 years ago

I've developed my own version to run directly on HAP-NodeJS, so not a Homebridge plugin.. (obviously, the Eve integration is based upon your work). But I have found, my logic seems to make sense and not sure why working in yours as EveHome wouldn't know about the last event time when is based on the time from the first event to the current time

https://github.com/n0rt0nthec4t/HAP-NodeJS-Accessories/blob/master/HomeKitHistory.js

simont77 commented 4 years ago

Ok, I understand. You said that "lastActivation is number of seconds since the first event to the last event", but this what fakegato does, since, as I said, InitialTime is set by fakegato to the time of the first event in the history. I suppose that in your code you are not setting InitialTime properly. Indeed, I do not see any getInitialTime method in your code.

n0rt0nthec4t commented 4 years ago

The following code gets the last entry time. the reftime is what I'm using and this is set elsewhere to the first event time (of the type)

HomeKitHistory.prototype.__EveLastEventTime = function() { // calculate time in seconds since first event to last event. If no history we'll use the current time as the last event time var historyEntry = this.lastHistory(this.EveHome.type, this.EveHome.sub); var lastTime = Math.floor(new Date() / 1000) - (this.EveHome.reftime + EPOCH_OFFSET); if (historyEntry && Object.keys(historyEntry).length != 0) { lastTime -= (Math.floor(new Date() / 1000) - historyEntry.time); } return lastTime; }

Thanks for your work and answering my initial question. I couldn't seen in your coding where this.lastActivation is set or how being used, so hence why I questioned the readme which started it had to be the current time (moment().unix() - getInitialTime() as the current time maybe not be the time of the last event

simont77 commented 4 years ago

Now I understand. Yes, I was implying that you update lastActivation as soon as a new event occurs, so moment.unix == last event. If you want to update lastActivation at a different time you have to use the time of the last event.