simont77 / fakegato-history

Module to emulate Elgato Eve history
MIT License
167 stars 15 forks source link

Timer without adding extra entries #62

Closed tobekas closed 5 years ago

tobekas commented 5 years ago

Hi, I really like your lib and the timer handling. In my setup, sensor data are received via MQTT every ~50-70 seconds. I call your addEntry function every time when new data are received, so that a new history entry is generated every 10min from the average. This is working perfectly. Now, if one sensor suddenly stops sending data (going offline, battery low, ...) and consequently no entry is added within the next 10min-intervall (no addEntry call), I don’t want to have this „previous average extra entry“ generated. If the sensor is really off, gaps in the Eve app are absolutely ok.

Is it possible to use your timer for averaging values over the timer interval, but without adding extra entries if no data were added?

simont77 commented 5 years ago

Hi, at present this is not possible, and the current behavior was decided exactly to avoid gaps on the history. Actually @NebzHB implemented the timer section, and honestly now I cannot remember all the details, let’s see what he thinks

NebzHB commented 5 years ago

Thé problem is for the lazy temperature sensors that might not send data for something like an hour because the temperature didn't change above the threshold value, those will have gaps in history... so the current behaviour is more like a conservative way of thinking...

tobekas commented 5 years ago

Okay, I see your point. Nevertheless, it would be a great benefit to have an optional parameter (similar to disableTimer) for disabling the filling entries. So every Homebridge plugin could decide to use or not to use this functionally.

In my particular case, one of my sensor batteries was empty for ~3 days, sensor state was set to inactive, but the Eve history graph recorded a constant outdoor temperature of 7.2°C (every 10min for 3 days...). This is not what I expected for a temperature sensor.

It would be great if you could implement this (hopefully small) adaptation.

A big thank you for your great work so far!!

simont77 commented 5 years ago

At this moment I don’t have much time to devote to this. I will tag it as a feature request. Stay tuned

NebzHB commented 5 years ago

Hello, could you please test the disableRepeatLastData branch ? (see readme for usage)

tobekas commented 5 years ago

Hi NebzHB, thank you a lot for the implementation. I tested your modification but had no success so far. I added the new option as follows: let logSvc = new FakeGatoHistoryService('room', this, {storage:'fs', disableRepeatLastData:true}); I stopped calling addData after a while, but the last average was still added every next 10min.

I will debug this in the next few days. Maybe it could also be my fault. I'll let you know...

tobekas commented 5 years ago

I think i found the bug: You have to replace if(!this.disableRepeatLastData) by if(!fakegato.disableRepeatLastData). The keyword this in the callback refers to the service bundle object (subscribedServices within "fakegato-timer.js") and disableRepeatLastData is not a property of this bundle object. Its a property of this.service. :-)

Best regards

NebzHB commented 5 years ago

Or mine... I'll investigate too

NebzHB commented 5 years ago

Oh yeah indeed

NebzHB commented 5 years ago

fixed, could you try again ?

tobekas commented 5 years ago

Yeah, great. Now it's working as expected. Thanks a lot! It looks like a clean solution.

simont77 commented 5 years ago

Just published v0.5.3. Thanks