Integrate Siemens Logo (plclogo) in OpenHAB 2

Hello everybody, i think it’s time to post my rollershutter solution, i’m using nearly 10 Years :slight_smile: :slight_smile:
The motor self is controlled by follow UDF:
grafik
Hier is my UDF: RolladenMotor.pdf Rename pdf to zip!

Pulse on input I_UP drives the rollo high, pulse on I_DO drives the rollo down. The time rollo must be driven, are given by UDF parameters T_UP and T_DO respectively. As far output O_UP is high, the rollo drives high. After the time T_UP is past or O_UP is high and new pulse is send to I_UP, then O_UP goes low. Output IS_UP is set high, if pulse was send to I_UP and time T_UP is past. The same story is for I_DO, O_DO and IS_DO. Additionally UDF calculates the rollo position between 0 and 100 percent, as need by openHAB. Some safety is given too: It’s not possible to set O_UP and O_DO high same time. It’s software lock only. It’s much better to lock additionally in hardware: we are talking here about 220V (life-threatening)! The circuit is simple: One relay controls the direction and another switches 220V on or off. The rest of Logo side is quite simple (cool spider, isn’t it?) :
grafik

Let’s take a look on openHAB side. First we need some things:

  Thing pulse VB2_6  [ block="VB2.6", observe="NI23", pulse=500 ]
  Thing pulse VB2_7  [ block="VB2.7", observe="NI24", pulse=500 ]
  Thing memory VW116 [ block="VW116" ]

Then some items:

Switch  RolloHi       { channel="plclogo:pulse:LogoController:VB2_6:state" }
Switch  RolloDo       { channel="plclogo:pulse:LogoController:VB2_7:state" }
Contact RolloIsHi     { channel="plclogo:pulse:LogoController:VB2_6:observed" }
Contact RolloIsDo     { channel="plclogo:pulse:LogoController:VB2_7:observed" }
Switch  RolloHiActive { channel="plclogo:digital:LogoController:Q:Q19" }
Switch  RolloDoActive { channel="plclogo:digital:LogoController:Q:Q20" }
Number  RolloPosition { channel="plclogo:memory:LogoController:VW116:value" }
Rollershutter Rollo "Rollo" <rollershutter>

And at least some rules:

val Procedures$Procedure4<Command, SwitchItem, SwitchItem, Command>
LogoRolloLogic = [ Command ReceivedCommand, SwitchItem Up, SwitchItem Down, Command Direction |
  switch(ReceivedCommand) {
    case UP: {
      Up.sendCommand(OnOffType.ON)
    }
    case DOWN: {
      Down.sendCommand(OnOffType.ON)
    }
    case STOP: {
      if(Direction == UP) {
        Up.sendCommand(OnOffType.ON)
      } else if (Direction == DOWN) {
        Down.sendCommand(OnOffType.ON)
      } else if (Direction != STOP) {
        logDebug("LogoRolloLogic", "Direction " + Direction + " is not supported.")
      }
    }
  }
]

rule "RolloPosChanged"
when
  Item RolloPosition changed
then
  var Number value = RolloPosition.state as Number
  Rollo.postUpdate(Math.max(Math.min(value.intValue, 100), 0))
end

rule "RolloDrive"
when
  Item Rollo received command
then
  var Command dir = STOP
  if(RolloHiActive.state == OnOffType.ON) { dir = UP }
  else if (RolloDoActive.state == OnOffType.ON) { dir = DOWN }
  LogoRolloLogic.apply(receivedCommand, RolloHi, RolloDo, dir)
end

The theory of operation is quite simple: send pulses to properly blocks:-)

Kind regards,

Alexander