You can constrain the execution of the body of a rule that detects a connection/disconnection event by making such execution conditional on one of the functions described under Detecting Connectedness.
Generic Connection and Disconnection Events
A whenever rule can detect the establishment or breaking of a connection between two items irrespective of:
whenever item is connected to item
whenever item is disconnected from item
whenever any temp-control-monitor C
is connected to any outer-thermometer T
then start check-temp-progress (C, T)
whenever rule can detect the establishment or breaking of a direct connection between two items. The rule can fire for any direct connection, or only if the connection is:
whenever a connection [of class class]
is directly {connected to | disconnected from}
[an input of | an output of | the portname of] item
Examples:
whenever a connection of class pipe-connect is directly disconnected
from any tank T then start check-connection (T)
whenever any connection X is directly connected to
inflow-port of any tank T then start -inflow-rate (T, X)
whenever any connection of class my-connect is
directly connected to an input to any tank T
then conclude that the input-connection of T is true