# Rule with multiple ends

**URL:** <https://community.openhab.org/t/rule-with-multiple-ends/136424>\
**Category:** Scripts & Rules\
**Tags:** heating\
**Created:** [June 4, 2022, 2:03pm UTC](https://community.openhab.org/t/rule-with-multiple-ends/136424 "2022-06-04T14:03:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarveyHAB](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@MarveyHAB](https://community.openhab.org/u/MarveyHAB)\
**Post date:** [June 4, 2022, 2:03pm UTC](https://community.openhab.org/t/rule-with-multiple-ends/136424/1 "2022-06-04T14:03:19Z")

</div>

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 🙂  
Have a nice weekend  
BR  
Marvin

```auto
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

```

---

<div class="post-metadata">

**Author:** ![JustinG](https://community.openhab.org/user_avatar/community.openhab.org/justing/32/55948_2.png) [@JustinG](https://community.openhab.org/u/JustinG)\
**Post date:** [June 4, 2022, 3:59pm UTC](https://community.openhab.org/t/rule-with-multiple-ends/136424/2 "2022-06-04T15:59:36Z")

</div>

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.
