Good evening,
thanks for the reply. Meanwhile I found a solution and I want to summarize what I did. But first of all I want to thank the community for the support!!
1. Set-up
We installed for everything which can be switched in our house relay from Eltako (eS12-200-Uc) which are placed in a central controll box. Every switch in our house is wired with 24V and when pressed they give a short 24V-signal to the relay which switches the 220V for light etc… This works without any Raspberry Pi or something else. (This is very important as I still want to have light in case the Raspberry Pi is down). The aim was to use the 24V-cycle with the Raspberry Pi. The following wirering scheme shows what I did in my Test-set-up (Instead of 220V I used 24V and a LED this is much saver!!!).
Please find the corrected version below.
What happens at wicht event?
a) button is pressed
-
A signal is send to the relay which switches the relay and the light glows
-
A signal switches the optocoupler which isolates the Raspberry Pi from the 24V and a 3.3V Signal can pass the optocoupler and give a signal to the input pin B0 (It is important to set a pull-down resistor to this pin to prevent floating currents - thanks to the community for this hint!)
-
The 3.3V signal is used by openhab to change the symbol on the sitemap
b) Switching the switch on sitemap
-
A short 3.3V signal (100 milliseconds) is send from output pin A0 to the optocoupler
-
The signal let the 24V pass which switches the relay and the light is on or off
-
The switch shows the actual state of the light (on or off)
2. Installing the MCP23017-binding
This is the part which cost me a lot of energy. Unfortunately the version which can be installed via Paper UI leads to an error thus I put the “org.openhab.binding.mcp23017-2.5.3-SNAPSHOT.jar”-file into the addon-folder after uninstalling the binding in Paper UI. That’s it Furthermore wiringPi and so on needs to be installed and the user “openhab” needs to be added to group “gpio” and “i2c”. (To be honest, I don’t know, if the last two steps are really necessary)
3. The code in openhab
I use two MCP23017 one only for inputs (address 20) and one only for outputs (address 24). I use this set-up, because in future I will use several MCP23017 and I wanted to check, if everything works. This is why I created two things:
Thing mcp23017:mcp23017:input1 "MCP23017 Input 1" [address=20,bus=1] {
//input-Pins
Type input_pin : input#A0
Type input_pin : input#A1
Type input_pin : input#A2
Type input_pin : input#A3
Type input_pin : input#A4
Type input_pin : input#A5
Type input_pin : input#A6
Type input_pin : input#A7
Type input_pin : input#B0
Type input_pin : input#B1
Type input_pin : input#B2
Type input_pin : input#B3
Type input_pin : input#B4
Type input_pin : input#B5
Type input_pin : input#B6
Type input_pin : input#B7
}
Thing mcp23017:mcp23017:output1 "MCP23017 Output 1" [address=24,bus=1] {
//output-Pins
Type output_pin : output#A0 [default_state="HIGH"]
Type output_pin : output#A1 [default_state="HIGH"]
Type output_pin : output#A2 [default_state="HIGH"]
Type output_pin : output#A3 [default_state="HIGH"]
Type output_pin : output#A4 [default_state="HIGH"]
Type output_pin : output#A5 [default_state="HIGH"]
Type output_pin : output#A6 [default_state="HIGH"]
Type output_pin : output#A7 [default_state="HIGH"]
Type output_pin : output#B0 [default_state="HIGH"]
Type output_pin : output#B1 [default_state="HIGH"]
Type output_pin : output#B2 [default_state="HIGH"]
Type output_pin : output#B3 [default_state="HIGH"]
Type output_pin : output#B4 [default_state="HIGH"]
Type output_pin : output#B5 [default_state="HIGH"]
Type output_pin : output#B6 [default_state="HIGH"]
Type output_pin : output#B7 [default_state="HIGH"]
}
The first one for inputs and the second for outputs. It is important to set default_state=”HIGH”
After that the following items were created:
Switch
living_room_led_switch
"Living room LED switch"
Switch
living_room_led_state
"Living room LED switch contact"
Switch
living_room_led_command
"Living room LED command"
{channel="mcp23017:mcp23017:output1:output#A0"}
Contact
living_room_led_contact
"Living room LED contact"
{channel="mcp23017:mcp23017:input1:input#B0"}
But why three switches for on light? The reason is, that otherwise a click on “living_room_led_switch” would lead to a second triggering of the “living_room_led_switch” via contact, as the input gets an impulse, too. The task of the four items are the following:
living_room_led_switch: is shown on the sitemap and will trigger the rule “living_room_led switch” (see below) if used via Basic UI or whatever.
living_room_led_state: saves the state of the light (ON or OFF) and is used on the sitemap (e.g. visibility=[living_room_led_state==ON]
)
living_room_led_command: This switch is triggerd over a rule by the “living_room_led_switch” and is the only one which is connected to the thing (adress=24 => Output)
living_room_led_contact: This is the conntact wich is conected to the input (adress=20 => Input) and will trigger the second rule, if a button is pressed
Let’s have a look at the rules:
rule "living_room_led switch"
when
Item living_room_led_switch received update
then
living_room_led_command.sendCommand(ON)
Thread::sleep(100)
living_room_led_command.sendCommand(OFF)
end
rule "living_room_led contact"
when
Item living_room_led_contact changed to CLOSED
then
if (living_room_led_state.state == ON) {
living_room_led_state.sendCommand(OFF)
}
else
living_room_led_state.sendCommand(ON)
end
The rule “living_room_led switch” reacts on a press of “living_room_led_switch” and set “living_room_led_command” to state “ON” for 100 milliseconds. This is because the Eltako is a latching relay which reacts on short impulses. The second rule reacts on an input and changes, depending on the state of “living_room_led_state”, the state of “living_room_led_state” which is important for the switch which is shown on the sitemap:
sitemap Test label="Test" {
Frame label="Test" {
//Shows the switch depending on its state
Switch item=living_room_led_switch label="Licht ON" icon="switch-off" mappings=[ON="ON"] visibility=[living_room_led_state==OFF]
Switch item=living_room_led_switch label="Licht OFF" icon="switch-on" mappings=[ON="OFF"] visibility=[living_room_led_state==ON]
}
}
Both switches are the same with an different label
and mapping
via its parameter visibility
. On is shown if "living_room_led_state is “ON” and one if it is “OFF”.
3. And now?
I have to create a circuit board, solder it and bring it to from “dev” to “prod”. After everything is done (which can take a while) I will open a new thread in which I explain everything in detail
Once again thanks!
Best regards
BrainPain