Attempting to use Kapacitor to measure three batches

I am currently trying to use a TICKscript to measure three values and compare them. They are all sampled at different intervals, one is sampled every 5 minutes and the other two every 30 minutes, but can also be sampled at random if viewed. I am not getting any alerts even though I should have quite a few. I have tried it with and without the stateDuration node. Here is the script:

var db = ‘edgex’

var rp = ‘autogen’

var measurement = ‘rtu’

var groupBy = [‘device’]

var whereSpaceTempFilter = lambda: (“resource_name” == ‘SpaceTemp’) AND isPresent(“value”)

var whereCoolingSPFilter = lambda: (“resource_name” == ‘EffCoolingSPT’) AND isPresent(“value”)

var queryTemp = ‘’‘SELECT mean(“value”) as “spaceTemp” FROM “edgex”.“autogen”.rtu WHERE (“resource_name” = ‘SpaceTemp’)’’’

var queryCoolSP = ‘’‘SELECT mean(“value”) as “effCoolingSP” FROM “edgex”.“autogen”.rtu WHERE (“resource_name” = ‘EffCoolingSPT’)’’’

var queryHeatSP = ‘’‘SELECT mean(“value”) as “effHeatingSP” FROM “edgex”.“autogen”.rtu WHERE (“resource_name” = ‘EffHeatingSPT’)’’’

var name = ‘Space Temp Batch Rule’

var idVar = name + ‘-{{.Group}}’

var message = ’ {{.ID}} {{.Name}} {{.TaskName}} {{.Group}} {{.Tags}} {{ index .Tags “value” }} {{.Level}} {{.Fields}} {{ index .Fields “value” }} {{.Time}}’

var idTag = ‘alertID’

var levelTag = ‘level’

var messageField = ‘message’

var durationField = ‘duration’

var outputDB = ‘chronograf’

var outputRP = ‘autogen’

var outputMeasurement = ‘alerts’

var triggerType = ‘threshold’

var spaceTemp = batch
|query(queryTemp)
.period(15m)
.every(2m)
.groupBy(time(20m), ‘device’)
.align()
.fill(‘previous’)

var effCoolingSPT = batch
|query(queryCoolSP)
.period(1h)
.every(2m)
.groupBy(time(2h), ‘device’)
.align()
.fill(‘previous’)

var effHeatingSPT = batch
|query(queryHeatSP)
.period(1h)
.every(2m)
.groupBy(time(2h), ‘device’)
.align()
.fill(‘previous’)

var joined = spaceTemp
|join(effCoolingSPT, effHeatingSPT)
.as(‘m1’, ‘m2’, ‘m3’)
.tolerance(1h)

var trigger = joined
|stateDuration(lambda: “m1.spaceTemp” > “m2.effCoolingSP” OR “m1.spaceTemp” < “m3.effHeatingSP”)
.unit(1m)
|alert()
.crit(lambda: “state_duration” > 4)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.log(’/tmp/alerts.log’)

trigger
|eval(lambda: float(“m1.spaceTemp”))
.as(‘spaceTemp’)
.keep()
|eval(lambda: float(“m2.effCoolingSP”))
.as(‘effCoolingSP’)
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag(‘alertName’, name)
.tag(‘triggerType’, triggerType)

trigger
|httpOut(‘output’)

Unsure of what I am doing wrong.

A little bit more context. When I run these commands in Influx 1.8, straight from the logs of Kapacitor.

SELECT mean(value) AS effCoolingSP FROM edgex.autogen.rtu WHERE (resource_name = ‘EffCoolingSPT’) AND time >= ‘2021-08-24T14:36:00Z’ AND time < ‘2021-08-24T15:36:00Z’ GROUP BY time(2h, 0s), device fill(previous)

The timestamp is: 1629813600000000000

SELECT mean(value) AS effHeatingSP FROM edgex.autogen.rtu WHERE (resource_name = ‘EffHeatingSPT’) AND time >= ‘2021-08-24T14:36:00Z’ AND time < ‘2021-08-24T15:36:00Z’ GROUP BY time(2h, 0s), device fill(previous)

The timestamp is: 1629813600000000000

SELECT mean(value) AS spaceTemp FROM edgex.autogen.rtu WHERE (resource_name = ‘SpaceTemp’) AND time >= ‘2021-08-24T15:21:00Z’ AND time < ‘2021-08-24T15:36:00Z’ GROUP BY time(20m, 0s), device fill(previous)

The timestampe is: 1629818400000000000

Hello @Ryebot33,
I’m afraid I don’t know. I’ve tagged our Kapacitor engineer in an issue. I hope he can help:

Any update on this? I have attempted using streams and windows as well, but unsure if that is the correct way to do it or not.