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