mondgans
(Falko Wiese)
April 6, 2022, 2:27pm
1
I want to log some statistical data with the timestamp of yesterday.
So I created a custom input, which runs short after midnight, to read the data and log as some hours ago.
I tried:
import datetime
...
tstamp = datetime.datetime.now() - datetime.timedelta(hours=4)
...
self.value_set(0, val, timestamp=tstamp)
self.value_set(1, val, tstamp)
but the values are still logged with the current time.
What am I doing wrong?
1 Like
Timestamps are stored in UTC, so try datetime.datetime.utcnow()
mondgans
(Falko Wiese)
April 6, 2022, 8:18pm
3
Unfortunately there is no change.
Found this while debugging
2022-04-06 21:37:54,013 - DEBUG - mycodo.controllers.controller_input_db38c8c5 - Adding measurements to InfluxDB with ID db38c8c5-8df1-4f21-8ec9-d243e69fd614: {0: {'measurement': 'energy', 'unit': 'kWh', 'value': 1.26, 'timestamp_utc': None}, 1: {'me...
based on the definition of value_set()
def value_set(self, chan, value, timestamp=None):
...
if timestamp:
self.return_dict[chan]['timestamp_utc'] = timestamp
else:
self.return_dict[chan]['timestamp_utc'] = datetime.datetime.utcnow()
the timestamp_utc should at least be the UTC timestamp but not “None”
Seams the information is lost somewhere in between.
I think I figured out the issue and committed a fix.
committed 02:49AM - 07 Apr 22 UTC
Upgrade to master and see if the issue is resolved. You will need to have in INPUT_INFORMATION the following key/value pair to indicate not to set all measurements to the same timestamp:
'measurements_use_same_timestamp': False
mondgans
(Falko Wiese)
April 7, 2022, 7:47pm
5
Hey Kyle,
this works as expected.
Thank you for your fast support.
Falko
1 Like