[SOLVED] Rule retriggering Item state

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Plus Rev 1.3
    • OS: Raspbian GNU/Linux 10 (buster)
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
    • openHAB openHAB 2.5.1-2 (Release Build)
  • Issue of the topic: I’m trying to achieve a Temprature conversion because I have 2 Xiaomi WIFI Outlets that report temperature but not in any recognizable scale (Celsius, Fahrenheit and not even Kelvin)

This are my first steps on Openhab so after reading I decided to arithmethically resolve the problem substracting 17 units to the Item.state value using a Rule. All went ok, bur the problem is that Item.postUpdate fires the Rule again entering on a crazy infinite loop of retriggering…It seems that everything is taken as change, not just the reports fired by the channel as I thought it could be.

Is there a way to prevent that Item.postUpdate retriggers the Rule? Am I using the wrong part of Openhab for the task and did I have to use Scripts for this?

Thanks and sorry for the newbiness!
:smile:

  • Items configuration related to the issue
    Number:Temperature   MiPowerPlug1Temperature     "Temperature" (gXiaomiPlug)  {channel="miio:generic:07AC1265:temperature"}

    Number:Temperature   MiPowerPlug2Temperature      "Temperature" (gXiaomiPlug)       {channel="miio:generic:07AC1237:temperature"}
  • Rules code related to the issue
rule "allxiaomiplugstemps"

    when

        Item MiPowerPlug2Temperature changed or

        Item MiPowerPlug1Temperature changed

    then

    var newValue = (triggeringItem.state as QuantityType<Temperature>).intValue

    newValue = newValue - 17

    triggeringItem.postUpdate(newValue)

    logInfo("gXiaomiPlug", triggeringItem.state.toString)

    end

Have it update a different item. For example, your source item could be “MiPlug1RawTemperature” and your final item is “MiPlug1Temperature”.

For one item or two items, this is very easy. If you anticipate more, look at the design pattern for associated items. You can name them appropriately, put them in a group, and get them all updated automatically. It makes sense if you anticipate more of these sensors.

Nice! Thanks John!!