[SOLVED] Triggering a rule if item changed from X to Y

  • Platform information:
    • Hardware: Raspberry PI 3B+
    • OS: Raspbian 9 (stretch)
    • openHAB version: 2.5.0~M1-1

I have a solar panel system and I’m trying to optimize the usage of the energy delivered by that system rather than importing from the outside net. To that end, I want to create a rule that takes care of the following:

  • When somebody starts the dishwasher, openHab will detect that the dishwasher starts using energy through a sensor (here item MF_KIT_Dishwasher_Z039_MeterWatts).
  • When the dishwasher is idle, it will occasionally consume up to 5W from reasons unknown to me, hence I can not test if the dishwasher goes from 0 to some value !=0; I need to test against two intervals 0-7W and above 7W
  • Already solved, but fyi: if the solar array is delivering enough extra power to support the dishwasher, openHab will simply let the dishwasher start. If the power delivered is not enough at present, openHab will check the weather forecast and predicted solar elevation for the coming hours and if it deems the probability high enough for the solar array to deliver the energy needed, ask the user if it is acceptable to postpone the start until enough power is available.

The problem
I am trying to trigger a rule based on an item changing from a value (here <7.0) to another value (here >=7.0). I am aware that I could use a construct where I trigger the rule if the item changes and then do testing in the logic of the rule itself but I thought placing the triggering logic in the “when-statement” would save false triggerings of the rule. So here is a simplified variant of what I tried:

rule “dishwasherStarted”
Item MF_KIT_Dishwasher_Z039_MeterWatts changed from <7.0 to >=7.0
then {
logWarn(“BPH_Test”, “The dishwasher started, check production and forecast for later”)

Needless to say, this (and a multitude of variants I have tried) do not work… The error logged is:

2019-08-01 00:21:48.884 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘scenes.rules’ has errors, therefore ignoring it: [84,57]: no viable alternative at input ‘<’ [84,65]: no viable alternative at input ‘>=’

I was under the impression that the “when Item A changed from X to Y” construct could be used and that e.g. less than something should be interpreted as a state but that doesn’t seem to be the case or am I getting it wrong? Having read all documentation I can find on rules and triggers I can not find a conclusive clue but a thread ([SOLVED] Rule when item changed to below a certain value) seems to indicate similar problems.

Is it possible to construct a trigger along the above lines or do I have to revert to “when A changed” construct withe tests inside the rule and have it trigger the rule hundreds of times per day?

Best /Brus-Per

No that won’t work, it’s not a number or enumerable type.
Revert to “…changed” and do the evaluation inside the rule. Nothing wrong with that, you can do it 1000 times a day without that it creates noticeable load.

1 Like

i think it is possible though, i faced a similar issue with light sensors to set tresholds.

use https://www.openhab.org/addons/transformations/scale/#scale-transformation-service

Create a proxy item (an item liked to the same smart meter channel that gives you the Watts consumed by your dishwasher)… call it i.e. Dishwasher_Treshhold, in your items file:

Switch Dishwasher_Treshold "Dishwasher status [SCALE(dishwasher.scale):%s]"
(i am unsure whether it can be a switch , maybe a text item? play with it)

In your transform folder add the above mentioned dishwasher.scale file


Now you can use it as a switch trigger for rules that will fire only when the wanted event happens, and not at any fluctuation of the watts as measured by your smart meter :slight_smile:

1 Like

Thnk you, Dario. Innovative approach! I will try it asap.