Cloud trigger: Alarm change
on compare of attribute value vs. property value on property
change
Use Case
An alarm needs to be published when a value is outside of a high value set point and a low value set point.
To solve this requirement, temperature set points are stored as attributes for what is deemed a high value and what is deemed a low value. The attributes used for these set points can be dynamically modified.
Thing Definition
The thing's thing definition has a property for the temperature value. Attributes are used for the high and low attributes. An alarm with three states is also defined:
- Property for temperature: temperature
- Attribute set point for high temperature: highthreshold
- Attribute set point for low temperature: lowthreshold
- Alarm for temperature: tempalarm
- Alarm States:
- 0 = Normal
- 1 = Low
- 2 = High
Cloud Trigger variables
Event Variables
$(event.thing.key) - The key of the thing that initiated the cloud trigger.
$(event.prop.value) - The data value of the Publish Property action (or property.publish API) that initiated the cloud trigger.
Action Variables
$(action.X.value) - The result value for action block X.
Property.change cloud trigger event
A cloud trigger is executed when a property change
occurs for the temperature property for all things
that have this thing definition.
Thing.attr.find action
The system first finds the attribute for the high set point (highthreshold) for the thing that caused the event. This is in the event variable $(event.thing.key) from the suggestions list. The value is stored temporarily as $(action.0.value).
Note: The $(action.X.value) action variable references
the action block numbered X. In this case we are using 0 as
it represents action block 0 for this thing.attr.find
action.
Math.if action
The cloud trigger then does a math.if action to compare the property value from the event, $(event.prop.value), to see if it is greater than the high threshold attribute value $(action.0.value).
If the property value is greater than the attribute
value, then the success path is followed to publish an
alarm.
Alarm.publish action
If the temperature property is greater than the
highthreshold attribute for the high set point,
the tempalarm alarm is published with the high
alarm state of state 2.
Thing.attr.find action
If the temporary property is not greater than
the highthreshold attribute for the high set
point, the lowthreshold attribute for the low set
point is stored temporarily as $(action.3.value).
Math.if action
The cloud trigger then does a math.if action to compare the property value from the event, $(event.prop.value), to see if it is less than the action value, $(action.3.value).
If the property value is less than the attribute value,
then the success path is followed to publish an
alarm.
Alarm.publish action
If the temperature property is less than the
lowthreshold attribute for the low set point, the
tempalarm alarm is published with the high alarm
state of state 1.
Alarm.publish action
If the temperature property is not less than the
lowthreshold attribute for low set point,
the tempalarm alarm is published with the normal
alarm state of state 0.