PLCLogo Solution: Logo Output Switching

Tags: #<Tag:0x00007f617ef8d130>

This is a wiki article and can be improved by everyone. Please do!

Problem Statement

How to switch a Logo-output for lights or power outlets via openHAB and in parallel via a physical wall-switch which is directly connected to a Logo-input? The status of the Logo-output shall be correctly monitored.

Concept

A proxy-item is used for the UI to store the on/off state (for visualisation) and for user-interaction. UI-commands are sent to the NI-item (pulse) which toggles the Logo’s relay (Q-output). Events originating from Logo (physical wall-switch pressed causing relay changes) will update the proxy-item by the rule. A rule triggered once at openHAB startup initializes the proxi-item and writes the current relay status into it.

Solution

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

LOGO! Configuration (LOGO! SoftComfort Diagram Editor)
Logo_light_switch

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=1000 ]
{
  Thing  digital Outputs [ kind="Q" ]
  Thing pulse     VB100_1  "Logo7 NI4"  [ block="VB100.1", observe="VB100.1", pulse=200  ]
}

Items (logo7.items)

Switch  Logo7_Q12   "Licht Wand [%s]" <light>    { channel="plclogo:digital:Logo7:Outputs:Q12" }
Switch  Logo7_NI4   "NI4"    { channel="plclogo:pulse:Logo7:VB100_1:state" }
Switch  Wall_Light_proxy "Light Wall" <light> (Wall_proxy, gLight)

Rules (logo7.rules)

rule "Switch Light Wall Logo"
when
    Item Logo7_Q12 changed or                         // light changed external
    Item Wall_Light_proxy received command            // light changed internal
then
    if(receivedCommand==ON || receivedCommand==OFF) { // ensure there was a received command, so second item triggered rule
        if (Logo7_Q12.state != receivedCommand) {     // only if state changed
            Logo7_NI4.sendCommand(ON)                 // send a pulse
        }
    }
    else {                                                // no trigger from proxy switch, so state changed externally
        if (Logo7_Q12.state != Wall_Light_proxy.state) {  // if state changed really
            Wall_Light_proxy.postUpdate(Logo7_Q12.state)  // update the state without triggering the rule
        }
    }
end

rule "Startup"
when
   System started
then
   // logInfo("StartUp", "System startup: Logo states flushed into proxy switches")
   Wall_Light_proxy.postUpdate(Logo7_Q12.state)  // update the state at startup
end

Sitemap (default.sitemap)

sitemap default label="Home" {
Frame label="Light Switch" icon="attic" {
        Switch item=Wall_Light_proxy mappings=[OFF="AUS", ON="EIN"]
        Switch item=Logo7_NI4 label="Debug NI4 (do not touch)"  // remove this line
   }
}

Revision History

  • Janaury 2019: original post for openHAB version 2.4 with Logo 0BA7
  • February 2019: completely re-edited, this works nicely.

Troubleshooting

  • none

Next Ideas

  • none

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.

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.

I don’t know Logo and am not quite sure what your rule is doing, but offer a possible alternative approach.

I have lighting controlled by by pulse relay types. There are physical push-on, push-off buttons for manual control.
openHAB has an Item for a simulated pushbutton, and another Item monitoring the light circuit actual state (on or off).

I don’t use timers for simulated pushbutton release, it works like this -

UI or rules send command to “Light” Item (autoupdate is disabled).
A rule listens for commands and if command ON/OFF does not match current light state, issues a command to “pushbutton”

A rule listens for “Light” state changes.
If simulated “pushbutton” is pressed, release it and also do anything else that needs to be done, this was an automatic event.
If our “pushbutton” not pressed, it was a manual event and we can do whatever might be needed for that case.

This is a idea of switching Outputs without using Pulse things and with groups

Problem Statement

How to switch a Logo-output for lights or power outlets via openHAB and in parallel via a physical wall-switch which is directly connected to a Logo-input? The status of the Logo-output shall be correctly monitored. With pulse-items there is a chance of hanging pulses. so that a solution without pulse-items is desirable.

Concept

A proxy-item is used for the UI to store the on/off state (for visualisation) and for user-interaction. UI-commands are sent to the M-item (switch) which toggles the Logo’s relay (Q-output). Events originating from Logo (physical wall-switch pressed causing relay changes) will update the proxy-item by the rule. A rule triggered once at openHAB startup initializes the proxi-item and writes the current relay status into it.

Solution

LOGO! Configuration (LOGO! SoftComfort Diagram Editor)

Things (logo.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:Logo [ address="192.168.178.21", family="0BA8", localTSAP="0x3000", remoteTSAP="0x2000", refresh=200 ]
{
  Thing digital  Outputs [ kind="Q" ]
  Thing digital  Marker [ kind="M"]
}

Items (logo.items)

Group:Switch Logo_M
Group:Switch Logo_Q
Group:Switch:OR(ON,OFF) Logo_proxy "Lights [%d]"
Switch  Logo_M1  (Logo_M)   { channel="plclogo:digital:Logo:Marker:M1"}
Switch  Logo_Q1   (Logo_Q)  { channel="plclogo:digital:Logo:Outputs:Q1"}
Switch  Logo_proxy_1   "Light Q1" (Logo_proxy)
//Switch  Logo_M2  (Logo_M)   { channel="plclogo:digital:Logo:Marker:M2"}
//Switch  Logo_Q2   (Logo_Q)  { channel="plclogo:digital:Logo:Outputs:Q2"}
//Switch  Logo_proxy_2   "Light Q2" (Logo_proxy)
//etc...

Rules (logo.rules)

rule "Logo lights"
when
    Member of Logo_Q changed or                         // light changed external
    Member of Logo_proxy received command               // light changed internal
then
    val Input = triggeringItem                          //Logo_proxy_x or Logo_Qx
    if(receivedCommand==ON || receivedCommand==OFF) {   // ensure there was a received command, so second item triggered rule          
        
        val Nummer=Input.name.split("_").get(2)         //gets number of input/output
        val Logo_Qx= Logo_Q.members.findFirst[ t | t.name == "Logo_Q"+Nummer ]
        val Logo_Mx= Logo_M.members.findFirst[ t | t.name == "Logo_M"+Nummer ]
        if (Logo_Qx.state != receivedCommand) {         // only if state changed
            if (Logo_Mx.state == OFF ){                 // change State of M
                Logo_Mx.sendCommand(ON)                 
            }
            else {
                Logo_Mx.sendCommand(OFF)                // change State of M
            }
        }
    }
    else {                                              // no trigger from proxy switch, so state changed externally
        val Nummer=Input.name.split("Q").get(1)
        val Logo_proxy= Logo_proxy.members.findFirst[ t | t.name == "Logo_proxy_"+Nummer ]
        if (Input.state != Logo_proxy.state) {  // if state changed really
            Logo_proxy.postUpdate(Input.state)  // update the state without triggering the rule
        }
    }
end

rule "Startup"
when
   System started
then
   // logInfo("StartUp", "System startup: Logo states flushed into proxy switches")
   // update the state at startup
Logo_proxy.allMembers.forEach [ item|
        val Nummer = item.toString.split("_").get(2)
        val Nummer2 = Nummer.toString.split(" ").get(0)
        val Logo_Qx= Logo_Q.members.findFirst[ t | t.name == "Logo_Q"+Nummer2 ]
        item.postUpdate(Logo_Qx.state)
    ]
end

Sitemap (Logo.sitemap)

sitemap Logo label="Logo" {
    Frame label="Lights" icon="lightbulb" {
        Switch item=Logo_proxy_1 label="Light Q1" icon="lightbulb"
        Group item=Logo_proxy label="Logo lights" icon="lightbulb"
    }
}

The group Design saves 380 lines of rule-code for a Logo with 20 lights at its Outputs. For a new light only .items file has to be edited, with 3 new lines.

Revision History

  • changed to group based design

Troubleshooting

  • none

Next Ideas

  • none

Beauty of solution: No proxy switches, very simple rule, very deterministic, no pulses.

Problem Statement

How to switch a Logo-output for lights or power outlets via openHAB and in parallel via a physical wall-switch which is directly connected to a LOGO! input? The status of the Logo-output shall be correctly monitored.

Concept

A RS-switch is used to toggle the LOGO! output (Q) from a wall-switch, which is physically connected to the LOGO! input (I). Via network input (NI) LOGO! receives commands from openHAB. The NI has the states ON|OFF (no pulse) and reflects the status of Q. The NI serves as UI-control (user-interaction) and status-display (visualisation).
Events originating from LOGO! (physical wall-switch pressed causing relay changes) will update the NI (always follows Q by rule).
A rule triggered at openHAB startup initializes the NI and writes the current state of Q into it (important if Q has changed when openHAB was offline).

Solution

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

LOGO! Configuration (LOGO! SoftComfort Diagram Editor)

Rename to zip: my_Switch_test.zip.pdf (15.9 KB)
Things

Bridge plclogo:device:Logo7 "Logo7 PLC" [ address="192.168.xxx.yyy", family="0BA7", localTSAP="0x0200", remoteTSAP="0x0200", refresh=1000 ]
{
  Thing digital Inputs  "Logo7 Inputs"  [ kind="I" ]
  Thing digital Outputs "Logo7 Outputs" [ kind="Q" ]
  //
  Thing memory    VB100_4   [ block="VB100.4",  force=false ] // NI5 Light

Items

Switch  Logo7_Q8    "Q8"         { channel="plclogo:digital:Logo7:Outputs:Q8" } 
Switch  Logo7_NI5   "NI5 Light" <light> { channel="plclogo:memory:Logo7:VB100_4:state" }

Rule

rule "Switch Light"
when
    Item Logo7_Q8 changed                         // light status changed
then
    Logo7_NI5.sendCommand(Logo7_Q8.state.toString)
    // logInfo("Switch Light", "Q8 changed and Rule executed.")
end

// start-up rule for init
rule "Startup"
when
   System started
then
    logInfo("StartUp", "System startup: LOGO! states flushed into (proxy) switches")
    Logo7_NI5.sendCommand(Logo7_Q8.state.toString)          // update the state of lights into the NI
end

Sitemap

sitemap default label="Home" {
Frame label="Light Switch" {
        Switch item=Logo7_NI5 mappings=[OFF="AUS", ON="EIN"] // Light
        // debug
        Text item=Logo7_Q8   label="Logo7_Q8 [%s]"  valuecolor=[OFF="red", ON="green"] icon=switch // this hides the switcher-control
   }
}

Revision History

  • May 2020: openHAB version 2.5.0 with Logo 0BA7

Troubleshooting

  • none

Next Ideas

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

Problem Statement

Using the Comfort-Switch block in LOGO! How to switch such a Logo-output for lights or power outlets via openHAB and in parallel via a physical wall-switch which is directly connected to a LOGO! input? The status of the Logo-output shall be correctly monitored in openHAB.

Concept

A new Comfort-Switch block has been developed as UDF (User Defined Function). This has the known Trigger- and Reset-Input, but additionally a Set-Input (and a Switch-Input).
The Comfort-Switch’s Trigger-Input is used to toggle the LOGO! output (Q) from a wall-switch, which is physically connected to a LOGO! input (I). Via network input (NI) LOGO! receives commands from openHAB. The NI has the states ON|OFF (no pulse), is connected to the SW-Input and reflects the status of Q. In openHAB, the NI serves as UI-control (user-interaction) and status-display (visualisation).
Events originating from LOGO! (physical wall-switch pressed causing relay Q changes) must update the NI (NI must always follow Q by rule).
A rule triggered at openHAB-startup initializes the NI and writes the current state of Q into it (important if Q has changed when openHAB was offline).

Solution

Things, Items, Rules and Sitemap are identical to the solution with the RS-switch above.

Explanation of Comfort-Switch UDF with additional Set-input (pulse) and Switch-input (ON/OFF)
5 Functions:
1a: Trigger (pulse long) -> Q=ON (permanent).
1b: Trigger (puls short) -> Q=ON (temporary, switched Q=OFF after n seconds).
1c: Trigger pulse -> Q=OFF (if Q was ON).

2a: Set (positive edge) -> Q=ON.
2b: Reset (positive edge) -> Q=OFF (initial state)

Remark (for parallel operation of trigger and switches):

  • If Q=ON, then changes of Set-input must not ‘disturb’.
  • If Q=ON, then Trigger (pulse) must clear Q (and must not start another cycle)
  • Reset always clears Q (regardless whethr Q was set by trigger or Set-input).
    SW (Switch ON or OFF) triggers the Set/Reset-inputs when SW changes.

Thanks to supporters in the Siemens LOGO! Forum.

LOGO! Configuration (LOGO! SoftComfort Diagram Editor)
Here is a screenshot of what the UDF looks like:


Here is a screenshot of what the test-program looks like:

Rename pdf to zip: myComfort-Switch_UDF_L7.zip.pdf (16.3 KB)
(The edge-triggered OR-block are now integrated into the UDF.)

Revision History

  • June 2020: openHAB version 2.5.5-1 (Release Build) with Logo 0BA7

Troubleshooting

  • none

Next Ideas

  • none