Function not executed completely

Hi There,

I’m fighting with one of my rules - again :angry:

In this case, I’m using a function for make the rule more readable. But the function isn’t executed completely.

val org.eclipse.xtext.xbase.lib.Functions$Function4 setHeaterOperatingModes = [
    int HeaterModeMainComfortZoneValue,
    int HeaterComfortZoneValue,
    int HeaterOutbuildingsValue,
    int HeaterManualZoneValue |
      logInfo("Heating","Set State for MainComfortZone: " + HeaterModeMainComfortZoneValue)
      if (element1.state != HeaterModeMainComfortZoneValue) {
        logInfo("Heating","State for MainComfortZone was different from last state")
        sendCommand(element1, HeaterModeMainComfortZoneValue)
      logInfo("Heating","Set State for ComfortZone: " + HeaterComfortZoneValue)
      if (element1.state != HeaterComfortZoneValue) {
        logInfo("Heating","State for ComfortZone was different from last state")
        sendCommand(element1, HeaterComfortZoneValue)
      if (element1.state != HeaterOutbuildingsValue) {
        sendCommand(element1, HeaterOutbuildingsValue)

    // At the moment there is only the office in the manual zone
    if (Office_Operating_Mode_Manual.state == ON) {
      if (Office_Operating_Mode.state != 1) {
        sendCommand(Office_Operating_Mode, 1)
    } else {
      if (Office_Operating_Mode.state != HeaterManualZoneValue) {
        sendCommand(Office_Operating_Mode, HeaterManualZoneValue)

The relevant parts are the first two blocks “Main Comfort Zone” and “Comfort Zone”.

The rule is looking like this:

// Heating at noon
rule "Heating Switch Operating Mode at noon"
  Time cron "0 /5 9-17 * * ?"
  if (I_am_on_vacation.state == ON) {
    // Set all to freeze protection when on vacation
  } else {
    // 1 + 2 : Only heate on precense - reduce othervice
    if (Heater_Mode.state == 1 || Heater_Mode.state == 2) {
      sendCommand(Operating_Mode_Summer, OFF)
      if (Heater_Presence.state == ON) {
      } else {

When the rule is executed I’m getting the following log output:

2016-09-28 09:50:03.372 [INFO ] [g.openhab.model.script.Heating] - Set State for MainComfortZone: 1
2016-09-28 09:50:04.106 [INFO ] [g.openhab.model.script.Heating] - Set State for ComfortZone: 1
2016-09-28 09:50:04.135 [INFO ] [g.openhab.model.script.Heating] - State for ComfortZone was different from last state

BUT: The Value for the Comfort Zone isn’t set - so obviously “sendCommand(element1, HeaterComfortZoneValue)” isn’t executed and I have no Idea why :frowning:

Any Idea what wen’t wrong?


P.S.: One interesting thing, which might be a bug - When I add a log message with an error in it (Not on purpose), the function stops executing at the point of the log message but without logging an error message.

I think your P.S. points to the root cause. Lambdas unfortunately just seem to stop when there is an error in them.

I don’t see anything obviously wrong. There might be some issues with converting the HeaterComfortZoneValue to a format that element1 can understand. To avoid these sorts of problems it is better to use element1.sendCommand(HeaterComfortZoneValue) instead of the sendCommand action.

You can try wrapping the logic in a try catch(Throwable t) to see if you can catch the error to get a clue.