Downsampling to time/delta window

I am trying to write a stream TICKscript to down sample temperature data to configurable time/delta window, e.g. discarding points where temperature hasn’t changed by more than 0.5 degrees since last value up to one hour.

The following is my stream TICKscript:

var last_vals = stream
    |from()
        .measurement('some_measure')
    |last('temperature')
        .as('last_temperature')
    |window()
        .period(1h)
        .every(1h)
        .align()

var curr_vals = stream
    |from()
        .measurement('some_measure')
    |window()
        .period(5m)
        .every(10s)
        .align()

last_vals
    |join(curr_vals)
        .as('last_vals', 'curr_vals')
    |eval(lambda: if("last_vals.last_temperature" + 0.5 > "curr_vals.temperature" AND "last_vals.last_temperature" - 0.5 < "curr_vals.temperature", "last_vals.last_temperature", "curr_vals.temperature"))
        .as('m_temperature')

Please verify

Thanks,
Myron