Question on a trigger evaluation

I have a rule that had been working. It is pretty simple. It monitors the power reading from my HEM and stores the max power reading for the month.

I don't really look at it that often, but I had a issue with the HEM due to my recent migration from a C8 to C8pro. I have been checking out all my rules and I noticed that I had not got a notice of a max power update in a while.

See trigger below. The first action of my original rule set a string variable to %device%. If the variable did not contain HEM then it should be Triggered, I couldn't remember for sure what %device% would be equal to for the time trigger, so my rule assumes if %device% did not contain HEM then it's the monthly trigger.

The problem is that %device% is also being set to PeakPower when ever the PeakPower variable is changed. I am pretty sure it did not do that originally. Since %device% is PeakPower and does not contain HEM, it does the month end reset and PeakPower is set back to 0.

It was a simple fix to account for the extra trigger, but is this a change or has it always been that way? I am sure the rule worked when I originally created it. It was some time ago so not sure when it stopped working.

tldr: In the trigger below, should PeakPower changing trigger the rule?

Yes. It always has been this way.

Ok, I have changed some rules to use conditional triggers as they seem cleaner to me that way, and give more options, so maybe I changed that one and didn't test it.

Why did you title this thread about 'conditional trigger', when what you showed is not a conditional trigger at all?

Instead of triggering on a power change it triggers only if the power change is greater than the variable. So that is conditional, but your right not a conditional trigger.

I did this rule a quite some time ago, and I know it worked. I do tend to go back and change things, so perhaps I decided to but the evaluation in the trigger and did not test.

Probably just me but that doesn't seem intuitive that a change to the variable would trigger the rule. I assumed, wrongly, that it only evaluated the expression when the HEM updated. "Power level of HEM reports".

It turns out, the other issue I found was the main problem. PeakPower, a decimal hub variable, gets set to the HEM reading. So it should have been equal and not grater than the HEM power level. So I didn't see why it would re-trigger even if changing the variable was causing the trigger expression to be re-evaluated. I had a another local variable I used in the actions that I just noticed was a number. So in the transfer of the HEM reading the decimal part of the was being removed. So the new PeakPower level would always be slightly less than the current HEM reading. So that was why the rule re-triggered. If not for that error I don't think I would have realized I didn't completely understand how the trigger evaluation worked.

So now I see the error, it was me.

If you wanted a constant value for the comparison, then obviously that wouldn't trigger it. Suppose you'd used a device instead of a variable, asking if one device value is greater than another device value. Pretty clearly you'd expect that to always reflect the current relationship between the two devices, right? A variable is the same: why compare to a variable if you don't care what the variable value is? Your intuition works differently than mine, because to me it's obvious that changing the variable value should trigger the rule if the resulting comparison is true.

1 Like

Apparently it does. I was thinking of it as a conditional trigger, but, as you pointed out, it is not. If that expression evaluates to true then it triggers. So I now understand.

It occured to me, however, that I could use a conditional trigger. I then assumed it would work as I originally thought, but it still triggers when the variable is changed.

The first screenshot shows the trigger. It is now a conditional trigger that says trigger if HEM changes but only if it's value is > PeakPower.

In the second screenshot, it shows the log. The first line that says not triggered was a change of power on the HEM. The second line event occured after I manually changed the PeakPower hub variable to 0. The HEM did not change only the PeakPower variable, yet the rule triggered. Setting TrgDev to "PeakPower".

Is this expected?

It seems easy enough to test for %device% being set to PeakPower and exit the rule, or use two rules, or check the condition in the rule actions.

Please show the Event Subscriptions for this rule. Did you hit Update Rule after changing the trigger??

Not really relevant, see below from OP.

I did hit update. I just made sure. I opened rule, hit update rule and then clicked done. Same thing rule triggered when PeakPower set back to 0.

That's odd, and not right; the variable subscription is wrong. I just created a trigger like yours, and there is no Event Subscription to the variable. Please remove the trigger completely, hit Update and then check the Event Subscriptions. If there is still one for the variable, you will need to remove the entire rule and recreate it.

Apparently a hold over from original rule. I am pretty sure I deleted the original trigger before creating the new one.

This time after deleting the condition I closed the trigger page and checked to make sure the event subscription was gone and it was. I then tried to recreate the new trigger. The condition still existed but it would not let me use it as a conditional trigger. I could select it as the condition, but it would not give me the done with trigger button. I had to go to the condition manager and delete the condition. Then when I added the new trigger and recreated the condition again, it worked. The event subscription to the variable was gone and it did not trigger when I updated the variable.

Thanks