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)
Yes, you have to guard against all the variables.
AussieTraccar and Anton, thank you so much for your help and clear explanation. Really appreciate it
I already told you exactly how to solve it.