Tick script onstateChanges

kapacitor

#1

stream
|from()
.database(‘metricsData’)
.measurement(‘DeviceStatus’)
|alert()
.crit(lambda: “DeviceStatus” > 1)
.stateChangesOnly()
.log(’/tmp/DeviceStatus.log’)
.post(’************’)

hi people i am kinda new to tick script.
What am i m doing now thorught mqtt pushing the data to telegraf using mqtt plugin from telegraf to influxdb metrics are being pushed.
So i have written the above ticket script.Here the condition is deviceStatus is a metrics which will be getting updated every 1 min or max 3 mins.So whenever the value of deviceStatus increases above 1 i want to get notified to my application.and when ever values is 1 or <= 1 then also i want to be notified.In my post i have given my url to handle that part which works.But only issue is state change is not working properly and sometimes alert is not getting raised.Is this proper way.