This is my flux script:
import "date"
from(bucket: "B/1D")
|> range(start: date.truncate(t: -1h, unit: 1h), stop: now())
|> filter(fn: (r) => r._measurement == "kWh" and r._field == "last_value")
|> filter(fn: (r) => r.entity_id == "plug_computer_energy_total")
looks like if I has range with date truncate where time is relative, then don’t works, because this code working:
|> range(start: date.truncate(t: now(), unit: 1h), stop: now())
or
|> range(start: date.truncate(t: 2022-10-14T13:30:00Z, unit: 1h), stop: now())
Only workaround is using experimental.subDuration() function:
import "date"
import "experimental"
from(bucket: "B/1D")
|> range(start: date.truncate(t: experimental.subDuration(from: now(), d: 1h), unit: 1h), stop: now())
|> filter(fn: (r) => r._measurement == "kWh" and r._field == "last_value")
|> filter(fn: (r) => r.entity_id == "plug_computer_energy_total")
I’am using Raspberry Pi 4 with Home Assistant, where I have installed InfluxDB 1.8.10.
Query an absolute time range
Truncate time values using relative durations