Rule with multiple ends

Hi all,
is there any way that a rule can have multiple ends?
My goal is that openhab only sends a command when the state should be changed.
For example when my heater is already ON I don’t have to send the command ON again.
Openhab only should send a command when the state is changed. For example when the heater is OFF and the temperature drops under my goal temperature then it should send the command ON (but just one time. Not during every update).

i hope you can help me :slight_smile:
Have a nice weekend
BR
Marvin

rule "Heizung"
when
  Item Tempsensor_1 received update
then
  if (Tempsensor_1.state < Temperatur_1_soll_proxy.state)
  {
    if (Heizung_DW3.state == OFF) Heizung_DW3.sendCommand(ON) 
    else end
  }
  else
  {
    if (Heizung_DW3.state == ON) Heizung_DW3.sendCommand(OFF)
    else end
  }
end

In this case, the else end lines are just not necessary. The logic of your if statements already achieves exactly what you want. An if ... else ... statement runs its blocks exclusively. If the if block gets runs because the test expression evaluates to true then the else block will not get run; there’s no re-evaluation after the if block concludes.

So in you’re case the first level test will only ever run just the first block or the second block, never both. And within each of those blocks it will either send the command or it won’t.

However, to answer your question, the when...then...end structure is not part of the actual rule code, that is syntax to allow OH to parse the .rules files. That means that end is not the command you think it is. In rulesDSL, there is a way to stop execution of a block and that is the return command.