[C8P 2.5.2] %device% isn't set or cleared when rule called by "Run Actions"

I'm trying to detect how a rule is called.

If it is "triggered" by a defined trigger, the "%device%" value gets set properly.

However, if the device is triggered directly from any rule via "Run Actions" or from the rule's "Run Actions" button, that value remains at whatever it was previously set to.

This makes it impossible to detect when a rule is directly "run"--I was hoping/expecting that variable would at least be emptied out if a Run Actions caused the rule to execute (and, ideally, it would contain the actual rule name).

Thoughts? Is that possible-feasible?

@support-agent

Thanks!

There is not; this variable persists until overwritten, and there is no device with a manual "Run Actions" (among other possibilities). Some suggestions:

  • if you need the rule to do different things in different cases, just write a different rule (since you're in control of when either would be called) -- or find some way to combine these ideas, like "Run rule actions" to effectively share sets of actions among the rules if the differences are slight;
  • consider an alternative means, like checking a device state (or even time since event) as a condition in your actions rather than trying to specifically determine a trigger, if that meets your needs; or
  • state more about your intended goal, and someone can probably provide more specific ideas

Good luck!

I ended up creating a virtual button.

I hopefully found every place I was calling the routine and replaced it with the virtual button press.

That sets the "text" variable so I can tell what called it based on the button number.

(I need to be sure to never directly call that routine, now, because it will use the last invocation device).

I hate having big holes in my logic where I can't actually detect an anomaly like that.

But, I guess that's the best work-around I can get for now. If RM would clear that variable or, better yet, set it with the calling program, it would be better.