At the end I wrote three different tasks.
option task = {
name: "CAMERA",
cron: "0 0 * * *",
}
option v = {timeRangeStart: -1d, timeRangeStop: now()}
option entity_id = "0x00camera_temperature"
option prefix = "camera_"
data = from(bucket: "homeassistant-aprilia")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.entity_id == entity_id)
|> filter(fn: (r) => r["_field"] == "value")
data
|> aggregateWindow(every: 24h, fn: max, createEmpty: false)
|> set(key: "_field", value: prefix+"max_value")
|> yield(name: prefix+"max")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: min, createEmpty: false)
|> set(key: "_field", value: prefix+"min_value")
|> yield(name: prefix+"min")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: mean, createEmpty: false)
|> set(key: "_field", value: prefix+"mean_value")
|> yield(name: prefix+"mean")
|> to(bucket: "downsample-aprilia", org: "sineverba")
option task = {
name: "BALCONE",
cron: "0 0 * * *",
}
option v = {timeRangeStart: -1d, timeRangeStop: now()}
option entity_id = "0x00158d00067beedf_temperature"
option prefix = "balcone_"
data = from(bucket: "homeassistant-aprilia")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.entity_id == entity_id)
|> filter(fn: (r) => r["_field"] == "value")
data
|> aggregateWindow(every: 24h, fn: max, createEmpty: false)
|> set(key: "_field", value: prefix+"max_value")
|> yield(name: prefix+"max")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: min, createEmpty: false)
|> set(key: "_field", value: prefix+"min_value")
|> yield(name: prefix+"min")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: mean, createEmpty: false)
|> set(key: "_field", value: prefix+"mean_value")
|> yield(name: prefix+"mean")
|> to(bucket: "downsample-aprilia", org: "sineverba")
option task = {
name: "SALONE",
cron: "0 0 * * *",
}
option v = {timeRangeStart: -1d, timeRangeStop: now()}
option entity_id = "0x00158d0aaaaaa_temperature"
option prefix = "salone_"
data = from(bucket: "homeassistant-aprilia")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.entity_id == entity_id)
|> filter(fn: (r) => r["_field"] == "value")
data
|> aggregateWindow(every: 24h, fn: max, createEmpty: false)
|> set(key: "_field", value: prefix+"max_value")
|> yield(name: prefix+"max")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: min, createEmpty: false)
|> set(key: "_field", value: prefix+"min_value")
|> yield(name: prefix+"min")
|> to(bucket: "downsample-aprilia", org: "sineverba")
data
|> aggregateWindow(every: 24h, fn: mean, createEmpty: false)
|> set(key: "_field", value: prefix+"mean_value")
|> yield(name: prefix+"mean")
|> to(bucket: "downsample-aprilia", org: "sineverba")
You can see, same task duplicated x 3 times, difference is only the starting ENTITY.
IS it possible to merge them in only one task?