I have a flux task in Kapacitor which calculates the state of our heating:
from(bucket: "home_assistant/autogen", host: host, token: token)
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "climate.downstairs" and (r._field == "hvac_action_str"))
|> map(fn: (r) => ({
_time: r._time,
_measurement: "heating",
_field: "heating_state",
hour: date.hour(t: r._time),
_value: if r._value == "heating" then
1
else
0
}))
|> aggregateWindow(every: 15m, fn: max, createEmpty: false)
|> drop(columns: ["_start", "_stop"])
Currently, it can't be ported over because there's no way to implement that map()
.
What'd be good is if we could provide that map
within the yaml config with something like
custom_calls:
- >
|> map(fn: (r) => ({
_time: r._time,
_measurement: "heating",
_field: "heating_state",
hour: date.hour(t: r._time),
_value: if r._value == "heating" then
1
else
0
}))
in order to have it appended to the end of the query
Activity
04-Feb-23 16:19
assigned to @btasker
05-Feb-23 11:45
mentioned in issue #4
05-Feb-23 12:10
changed the description
05-Feb-23 12:41
mentioned in commit 28fd36007bc44674012dc1c95a8d9fa89c18e3cb
Message
Implement support for attribute
flux_calls
for utilities/python_influxdb_downsample#105-Feb-23 12:41
mentioned in commit 35f837599370b63d7a250a31c1e150f9ea8d88ef
Message
docs: update README to give example with custom flux calls (utilities/python_influxdb_downsample#1)
05-Feb-23 12:42
As of the commits above, we now support a list of flux calls via the
flux_calls
attributeThese are appended to the end of the query.
I decided it was better to append after the generated
window()
call because this allows things likereduce()
to be used.