Time based stream tasks in Kapacitor

I’m using Kapacitor 1.5. I want to write rule based on last time of record in measurement. I tried following but this does not seem to be possible:

dbrp "db"."rp"

var threshold = 1h
var period = 1h
var every = 1h

var data = stream
    |from()
        .measurement('last_logged')
        .groupBy('device-name')
    |window()
        .period(period)
        .every(every)
    |last('time')
        .as('last_logged_time')

var alert = data
  |alert()
    .message('Device {{ index .Tags "device-name"}} has not logged in ' + string(threshold))
    .crit(lambda: duration(unixNano(now()) - unixNano("last_logged_time"), 1u) > threshold)
    .critReset(lambda: duration(unixNano(now()) - unixNano("last_logged_time"), 1u) < threshold)

alert
  .slack()

I want to run this rule per hour. This rule is not working since last() expects a field, looks like “time” is not available as a field. Can someone suggest approach to make it work ?

I would prefer not to use batch mode since I don’t want those many queries (equal to cardinality of my data) to land on InfluxDB.

Thanks in advance!