TRIGGER for ALERTS NOT WORKING
drjakob opened this issue · comments
The triggers for Smax-Alerts are not working. Could it be that sensor reading "1" (true) is not recognized when trigger defined min=1, max=1?
I think I know what the problem is. It is the check if the trigger conditions are met. When an event is detected / fetched from the smaxtec event sensor, the sensor reading is set to 1 for the detected timestamp. Now here is what the check if the trigger conditions are met does (from models/trigger.rb) :
active = true
active &= (condition.from.nil? || condition.from <= reading.calibrated_value)
active &= (condition.to.nil? ||reading.calibrated_value < condition.to)
active &= (validity_period.nil? || (validity_period.hours.ago <= reading.created_at))
The line active &= (condition.to.nil? ||reading.calibrated_value < condition.to)
is checking if the sensor value is smaller than condition.to (max value, which is set to 1) and this is not true. If the max value is higher (e.g. 2), then this check would be correct.
So the fix is to either change this line to check if the sensor value is smaller or equal compared to the sensor reading (but I don't know if there are any side effects to this solution) or to change the max value for event sensor readings to 2.
I would prefer the smaller or equal solution, because it seems cleaner to me.
I hope this has no side effects on other triggers. Essentially this means (if I understand the check correctly), that before the trigger wasn't executed if the sensor reading value was the same value as the max trigger value. Only if it was below the max value, the trigger would fire.
You can change it to <=
if you want. Just beware that two consecutive sensor intervals will both fire on the boundary point.
the <
was intentional because of that
Okay, I see what the purpose of this was. This is what I meant by side effects, I knew that there was some reasoning behind that! 👍