=====Dynamic Attachment=====
Trigger can use the same Dynamic Attachment feature used in **Agency**.
This means that you can create a number of different //instances// of your trigger by attaching them to ARDI assets.
For example, you can create a trigger that logs when a door is opened or closed, then attach that to //every// asset with a type of **door**.
====How To Use It====
You'll need the [[decorators|decorators]] **@server** and **@attach**.
//@server// takes two parameters. The first is the ARDI server and the second is the ARDI site. This is used to set the ARDI server that needs to be queried for attachment points.
//@attach//
This is used to specify how the trigger should be attached. The first parameter is the attachment **type** and the second is the attachment **parameter**
Attachment types include **single**, **type** and **spider**.
A //single// attachment connects directly to the asset named in the parameter. \\
**@attach('asset','Door 1');**
A //type// attachment connects to all of the assets of the type chosen in the parameter. \\
**@attach('type','Door');**
A //spider// attachment connects to all assets //downstream// from the given asset, across the given relationship. \\
**@attach('spider','Door 1:Profile');**
====Asset Name Substitution====
If **{0}** appears in the data points for the trigger, the asset name will be substituted in its place.
Let's look at the decorators below...
@data('{0}.Status')
@attach('type','door')
If you had three doors named //Door A//, //Door B// and //Door C//, each of which had the type **door**, the above would create three triggers, one with an input of //Door A.Status//, one //Door B.Status// and one //Door C.Status//.
====Example====
@trigger
@riseandfall
@server('myardiserver','default')
@data('{0}.Status')
@attach('type','door')
@when(lambda o: float(o.Value()) == 0)
def DoorChangesState(o):
#Record how long the door was open
if o.Condition() == False:
duration = o.Range()[2]
o.Output(o.Name() + " Open Time",duration)
o.LogEvent(o.Name() + " Closed")
else:
o.LogEvent(o.Name() + " Open")