PLCLogo Solution: Logo Output Switching

Problem Statement

How to switch a Logo-output for lights or power outlets via openHAB and in parallel via a physical wall-switch. Logo shall use the comfort-switch block.

Concept

Like with the physical wall-switch (I21) the light shall be triggered ON (but permanently) and triggered OFF. Therefore the network-input (NI1) creates a short pulse, which is extended to 600ms. This is equivalent to a long-press of the wall-switch.

Solution

Here is a screenshot of what the result looks like.
example_light_switch

LOGO! Configuration (LOGO! SoftComfort Diagram Editor)
example_light_switch_logo
Comfort-Switch B003 switches Q7 permanently, if pulse us longer than 500ms. A short pulse switches-on Q7 only for 20s. B033 to assure that pulse from NI1 is longer than 500m (e.g. 600ms).

Things (logo7.things)
In this example, the IP address 192.168.xxx.yyy represents the Logo device’s address and must be adapted.The TSAP parameters must be adjusted as well.

Bridge plclogo:device:Logo7 "Logo7 PLC" [ address="192.168.xxx.yyy", family="0BA7", localTSAP="0x0200", remoteTSAP="0x0200", refresh=200 ]
{
  Thing digital Inputs "Logo7 Inputs"    [ kind="I" ]
  Thing digital Outputs "Logo7 Outputs"  [ kind="Q" ]
  Thing pulse     VB100_0  "Logo7 NI1"  [ block="VB100.0", observe="VB100.0", pulse=500  ]
}

Items (logo7.items)

Switch  Logo7_Q7    "Licht Essen [%s]" <light>         { channel="plclogo:digital:Logo7:Outputs:Q7" }
Switch  Logo7_NI1   "NI1"    { channel="plclogo:pulse:Logo7:VB100_0:state" }
// virtual Switch
Switch          FF_Dining_Light            "Licht"               <light>            (FF_Dining, gLight)

Rules (logo7.rules)

rule "Switch Light through Logo"
when
    Item Logo7_Q7 changed or                         // 1. light changed external
    Item FF_Dining_Light received command            // 2. light changed internal
then
    if(receivedCommand==ON || receivedCommand==OFF) { // ensure there was a received command, so second item triggered rule
        if (Logo7_Q7.state != receivedCommand) {      // only if state changed
            Logo7_NI1.sendCommand(ON)                 // send an ON
           // Logo7_NI1.sendCommand(OFF)                // send an OFF, maybe not required
        }
    }
    else {                                             // no trigger from proxy switch, so state changed externally
        if (Logo7_Q7.state != FF_Dining_Light.state) { // if state changed really
            FF_Dining_Light.postUpdate(Logo7_Q7.state) // update the state without triggering the rule
        }
    }
end

Sitemap (default.sitemap)

sitemap default label="Home" {
Frame label="Light Switch" icon="attic" {
        Default item=FF_Dining_Light label="Light (switch here)"
        Text  item=Logo7_Q7 label="Debug Q7"
        Default item=Logo7_NI1 label="Debug NI1 (do not touch)"
   }
}

Revision History

  • January 2019: original post for openHAB version 2.4 with Logo 0BA7
  • March 2019: openHAB version 2.4, PLClogo binding snapsot 2.5.0 with Logo 0BA7

Troubleshooting

  • Seems a bit shaky when toggling Light switch, esp. when toggling fast (status hicks up). NI might stay ON permanently (reset logo = stop logo, upload the config again, start logo). Likely solution: pulse time should be longer than Logo-refresh time (status of light = display as light-bulb from proxy-switch might not show correct status. Re-trigger with button-press, corrects this.)
  • It does not read the initial state (if logo-light was already on, and then starting up openHAB). Solution: take rule for ‘System started’ from 1st example.

Next Ideas

  • Rebuild own comfort-switch (UDF) not requiring a certain pulse-length for permanent ON and a reset-input.
1 Like