GT06 Power Cut Alarm - No Event Generation + Repeated Computed Attribute Problem

Anton Tananaev 24 days ago

I already told you exactly how to solve it.

AussieTraccar 24 days ago

As previously stated by Anton:

variable ? (expression if present) : (expression if missing)

Basically you should query the presence of ALL variables before testing logic against those variables.

Something like this might work, but this relies on having both charge and lastcharge variables present. The computation will return null if only one of the two variables are present, so you need to consider what results are returned under all possible conditions.

(charge ? lastcharge ? (charge != null && lastCharge != null && lastCharge != charge) ? charge == false ? "powerCut" : "powerRestored" : null : null : null)
Anton Tananaev 24 days ago

Yes, you have to guard against all the variables.

Haider 24 days ago

AussieTraccar and Anton, thank you so much for your help and clear explanation. Really appreciate it

Haider 9 days ago

I tried both approaches.

This one:

(charge ? lastcharge ? (charge != null && lastCharge != null && lastCharge != charge) ? charge == false ? "powerCut" : "powerRestored" : null : null : null)

does fix the log error, but the computed attribute stops working completely — it no longer generates any alarm when charge changes.

On the other hand, this expression:

lastCharge != null && lastCharge != charge ? (charge == false ? "powerCut" : "powerRestored") : null

does trigger the alarm correctly, but it still produces errors.

So it looks like the main issue is balancing null-safety with proper change detection. Right now I either get no computation at all, or working logic with errors in logs.

If anyone has a clean way to safely handle missing charge / lastCharge while still keeping the computed attribute working reliably, that would help a lot.

Haider 8 days ago

variable 'lastCharge' is undefined
variable 'charge' is undefined