DSL rule Item trigger and UoM

Hi,

I’d like use an Item as a DSL rule trigger which comes with a UoM. This is what I’d like to use as trigger:

Item <item> changed to <state>

How do I deal with the UoM in this case? The Item is defined as Number:ElectricPotential so it comes with unit “V”.

Thanks!

Try something like 24.0|°C

If that @AndrewFG 's suggestion doesn’t work try putting it in quotes: e.g. “25 V”.

However, this smells of an XY Problem. Putting the state there in the trigger is only ever going to trigger the rule on an exact match. If you used “25 V” the rule won’t trigger for 24 V, 26 V nor even for 25.0 V. There is only one case I can think of where it makes sense to use numbers in the trigger like this and no cases where it makes sense to use a number with a unit.

What are you trying to accomplish?

Thanks for your suggestions!

using 0|V is not accepted:

2025-01-31 14:14:36.526 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'pv.rules' has errors, therefore ignoring it: [192,37]: mismatched input '|' expecting 'then'

using “0 V” is at least accepted, will need to verify once it happens.

I’m monitoring my solar inverter’s string voltages. When it drops to 0V I’d like to make a few setting changes. I used a rule with an if statement but want to avoid the unnecessary triggering.

when
	Item <item> changed
then
	if(<item> == 0|V) {<do_stuff>}
end

The triggering doesn’t cost anything. At least it doesn’t cost significantly more than the if statement. The rule will still trigger and the value will be compared to your value. The only real difference is where the if statement lives.

With managed rules and the other rules languages something like this is better handled in a rule condition. JS’s rule builder and I think jRuby both support rule conditions similar to what you find in managed rules even with file based rules.

So I verified that this works when the Item is defined as Number with UoM - its basically a string compare of the specific value with its UoM.

Item <item> changed to "<value UoM>"

Sure, this may not have a significant impact on the rules engine. Still I was curious how it works with UoM and now I know :nerd_face: