ioBroker.history
ioBroker.history copied to clipboard
Cannot get earliest stored value (limit 1)
Describe the bug
I want to use sendTo
to get the first value (with the lowest timestamp) in history database. But that is not possible:
To Reproduce
Idea:
- Select all data since timestamp 0
- Ordered by date ascending
- Limit result to 1 value
sendTo('history.0', 'getHistory', {
id: 'yr.0.forecastHourly.0h.air_temperature',
options: {
start: 0,
end: Date.now(),
aggregate: 'none',
returnNewestEntries: false,
limit: 1,
}
}, async (historyData) => {
if (historyData.result.length > 0) {
let startTs = historyData.result[0].ts;
console.log(`Earliest vlaue -> ${formatDate(startTs, 'DD.MM.YYYY hh:mm:ss')}`);
}
});
The first value in my DB is from 1636560079478
-> 10.11.2021 (~ 1 year old).
But I receive: Earliest vlaue -> 09.11.2022 11:25:28
(today).
When I set the limit to 2000
, the result is Earliest vlaue -> 13.08.2022 18:25:29
.
Seems like the limit is applied to "the wrong side" of the result.
Versions:
- Adapter version: 2.2.0
Same behaviour with beta version 2.2.4
Yes this is because of the 0 as start ... this is handled as "not defined" ... try 1 (or use 1.1.2000 becausthe adapter was not exosting before that date at all)
Just checked the code start: 0
doesn't survive the option checks. start: 1
does the trick! Maybe you should check if options.start
is a number.
https://github.com/ioBroker/ioBroker.history/blob/24cb6c5f3fa40dc3fc435fd45eda801e79656739/main.js#L1224-L1226
No idea if this would be breaking for some visus or such ... no idea if someone sends start=0 to actually trigger this behaviour as it is now ... :-(
Ok, got it :) Feel free to close this issue
I leave open, maybe a README note might be an idea