Difference between smarthome:send and sendCommand in rule

I’m using OpenHAB 2.5 and have a bit of a “duh” moment right here.
Consider following items:

String Contact_Dining           "Esszimmerfenster" <window> (Dining)             {channel="homematic:HmIP-SWDM:[...]:1#STATE"}
String Dining_Thermostat_Window "Fenster [%s]"     <window> (Dining_Thermostat)  {channel="homematic:HmIP-eTRV-B:[...]:1#WINDOW_STATE" }

And this simple rule (the generic/specific difference is a result of trying to debug):

rule "Disable heating when window is open"
  Item Contact_Dining changed
  switch Contact_Dining.state {
    case "OPEN": {
      sendCommand(Dining_Thermostat_Window, OPEN)
    case "CLOSED": {

I have the following issue:

  • If I select “Window opened” from the dropdown in the Basic UI, the thermostat recognizes the state and turns down the temperature.
  • If I use smarthome:send Dining_Thermostat_Window OPEN in the console, log shows the command is sent and the thermostat does the same as above.
  • If I just open the window and have the rule send the command, log shows the command is sent … and nothing happens. Same issue when using postUpdate.

Why is there a difference? Does a rule have a different context that affects execution? I’m honestly a bit stumped and don’t quite know where to look further.

This rule is doing the same thing, no matter how you caused the event that triggered it. Could you add some logging to the rule and then post the openhab.log and events.log for the last scenario?

I don’t see it as related, but it’s odd to use both the sendCommand method and the action at the same time. Why not use one or the other? The method is usually more forgiving.

Edit: I just saw the Item types you are using. Are you sure these are the right types? How is your sitemap defined? I’m surprised that this…

… works, since you are sending OpenCloseType.OPEN and not “OPEN”. I don’t see how that would work for a StringItem. I would think that both Items should be defined as ContactType.

1 Like

I typed this just yesterday

1 Like

Well, they apparently are the right item types, but for some reason, smarthome:send does not cast OPEN to OpenClosedType; if I quote OPEN and CLOSED in the rules, the rule works, regardless of being used via the object method or with send command.

Thanks for the (indirect) suggestion about casting, and sorry for the late reply. :slight_smile:

1 Like

Thanks for the info!

The reason is that your Items are of String type. No matter what you do, they can never take a state which is an OpenClosedType.