[SOLVED] Room Automation using OpenHAB, KNXD and Raspberry Pi 3

Tags: #<Tag:0x00007f2fb0bafa68> #<Tag:0x00007f2fb0baf860> #<Tag:0x00007f2fb0baf680>

I am building a room automation system which has just lights and rollershutters.
I started with only lights for now but I am unable to configure OpenHAB.
I am able to read and write the bus which means my KNXD is working.
But I am unable to configure openHAB.

My openhab.cfg file on /etc/openhab/configurations path is as follows:

knx:ip=192.168.1.22
knx:busaddr=1.1.9
knx:ignorelocalevents=true
knx:type=ROUTER
knx:serialPort=/dev/ttyUSB0

My Items file:
Group Lights
Switch Left_Lights "Left Lights"(Lights) { knx="<1/1/51" }
Switch Right_Lights "Right Lights" (Lights) { knx="<1/1/52" }
Switch Centre_Lights "Centre Lights" (Lights) { knx="<1/1/53" }
Switch Other_Lights "Other Lights" (Lights) { knx="<1/1/54" }

My rules file:
sitemap default label="default"
{ Frame label = "F1 406" {
Switch item=Left_Lights label="Left Lights" mappings=[1="ON",0="OFF"]
Group item = Lights

Switch item=Right_Lights label="Right Lights" mappings=[1="ON",0="OFF"]
Group item = Lights

Switch item=Centre_Lights label="Centre Lights" mappings=[1="ON,0="OFF"] Group item = Lights

Switch item=Other_Lights label="Other Lights" mappings=[1="ON",0="OFF"] Group item = Lights
}
}

My rules file:

org.eclipse.smarthome.core.persistence
org.eclipse.smarthome.core.library.types
org.eclipse.smarthome.core.library.items
org.eclipse.smarthome.model.script.actions

rule "Switch ON Left Lights 1"
when
     Item Left_Lights changed [from OFF] [to ON]
then
     Left_Lights.sendCommand(ON)
end

rule "Switch ON Right Lights 2"
when
     Item Right_Lights changed [from OFF] [to ON]
then
    Right_Lights.sendCommand(ON)
end

rule "Switch ON Centre Lights"
when
     Item Centre_Lights changed [from OFF] [to ON]
then
     Centre_Lights.sendCommand(ON)
end

rule "Switch ON Other Lights"
when
     Item Other_Lights changed [from OFF] [to ON]
then
     Other_Lights.sendCommand(ON)
end
rule "Switch OFF Left Lights 1"
when
     Item Left_Lights changed [from ON] [to OFF]
then
     Left_Lights.sendCommand(OFF)
end

rule "Switch OFF Left Lights 2"
when
     Item Right_Lights changed [from ON] [to OFF]
then
     Right_Lights.sendCommand(OFF)
end

rule "Switch OFF Centre Lights"
when
    Item Centre_Lights changed [from ON] [to OFF]
then
     Centre_Lights.sendCommand(OFF)
end

rule "Switch OFF Other Lights"
when
     Item Other_Lights changed [from ON] [to OFF]
then
     Other_Lights.sendCommand(OFF)
end


Also, I have another doubt... My etc directory has 2 sub-directories openhab and openhab2. Is it normal?

Please use the code fences

No. Most likely you have installed in parallel OH1 & OH2
Get rid of the OH1 installation and use OH2 config files (for example: openhab.cfg is used in OH1)
For OH2, you should use /etc/openhab2/...) (e.g. /etc/openhab2/services/knx.cfg)

Done
Sorry I am new to this

To learn how to use the forum, send a message to @discobot with the subject “start new user” and “start new user” in the text box then follow the chat

Then when you have finished do the same with “start advanced user”

Thank you

Hello everyone!
After installing KNX Binding in PaperUI, I do not see knx.cfg file in services directory.
Is it normal?

the KNXv2 you mean…

@Dim I have installed binding-knx - 2.3.0

then, you won’t have a knx.cfg and you need to define your Bridge & Things

see here: https://www.openhab.org/addons/bindings/knx/#knx-binding

@Dim Thanks!

Hi All,
I am almost at the end of my work but still have some doubts

My Items file

Switch demoSwitch1 "Left_Lights1" <Lights> {channel="knx:device:bridge:generic:controlSwitch1" }
Switch demoSwitch2 "Left_Lights2" <Lights> {channel="knx:device:bridge:generic:controlSwitch2" }
Switch demoSwitch3 "Left_Lights3" <Lights> {channel="knx:device:bridge:generic:controlSwitch3" }
Switch demoSwitch4 "Center_Lights" <Lights> {channel="knx:device:bridge:generic:controlSwitch4" }
Switch demoSwitch5 "Other_Lights" <Lights> {channel="knx:device:bridge:generic:controlSwitch5" }

This is my rules file

import org.eclipse.smarthome.core.items
import org.eclipse.smarthome.core.persistence
import org.eclipse.smarthome.core.library.types
import org.eclipse.smarthome.core.library.items
import org.eclipse.smarthome.model.script.actions

rule "Switch_ON_LeftLights1"
when
     Item demoSwitch1 changed from OFF to ON
then
     demoSwitch1.sendCommand(ON)
end

rule "Switch_ON_LeftLights2"
when
     Item demoSwitch2 changed from OFF to ON
then
    demoSwitch2.sendCommand(ON)
end

rule "Switch_ON_LeftLights3"
when
     Item demoSwitch3 changed from OFF to ON
then
     demoSwitch3.sendCommand(ON)
end

rule "Switch_ON_CentreLights"
when
     Item demoSwitch4 changed from OFF to ON
then
     demoSwitch4.sendCommand(ON)
end

rule "Switch_ON_OtherLights"
when
     Item demoSwitch5 changed from OFF to ON
then
    demoSwitch5.sendCommand(ON)
end

rule "Switch_OFF_LeftLights1"
when
     Item demoSwitch1 changed from ON to OFF
then
     demoSwitch1.sendCommand(OFF)
end

rule "Switch_OFF_LeftLights2"
when
     Item demoSwitch2 changed from ON to OFF
then
     demoSwitch2.sendCommand(OFF)
end

rule "Switch_OFF_LeftLights3"
when 
     Item demoSwitch3 changed from ON to OFF
then 
     demoSwitch3.sendCommand(OFF)
end

rule "Switch_OFF_CentreLights"
when
     Item demoSwitch4 changed from ON to OFF
then
     demoSwitch4.sendCommand(OFF)
end

rule "Switch_OFF_OtherLights"
when
     Item demoSwitch5 changed from ON to OFF
then
     demoSwitch5.sendCommand(OFF)
end

My Sitemap file

sitemap default label="F1.406"
{
 Frame label="Lights" {
    Switch item=demoSwitch1 label="Left Lights 1" 
    Switch item=demoSwitch2 label="Left Lights 2" 
    Switch item=demoSwitch3 label="Left Lights 3" 
    Switch item=demoSwitch4 label="Centre Lights" 
    Switch item=demoSwitch5 label="Other Lights" 
   }
}

My Things file
I have used textual configuration instead of Discovery method

Bridge knx:serial:bridge [ 
    ipAddress="192.168.1.22",
    port=3671,
    serialPort="/dev/knx1", 
    type="TUNNEL",
    ignorelocalevents=true,
    readingPause=50, 
    responseTimeout=10, 
    readRetriesLimit=3, 
    autoReconnectPeriod=1
   ] {
      Thing knx:device:bridge:generic {
       Type switch-control        : controlSwitch1        "Control Switch Left1"        [ ga="<1/1/51" ]
       Type switch-control        : controlSwitch2        "Control Switch Left2"        [ ga="<1/1/52" ]
       Type switch-control        : controlSwitch3        "Control Switch Left3"        [ ga="<1/1/53" ]
       Type switch-control        : controlSwitch4        "Control Switch Centre"        [ ga="<1/1/54" ]
       Type switch-control        : controlSwitch5        "Control Switch Others"        [ ga="<1/1/55" ]
             }
       }

2018-07-26 09:33:19.958 [me.event.ThingUpdatedEvent] - Thing 'knx:serial:bridge' has been updated.
2018-07-26 09:33:19.961 [hingStatusInfoChangedEvent] - 'knx:serial:bridge' changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): failed to open serial port /dev/knx1

This is the error I am getting.

KNXD works fine as I am able to read and write the bus using vbusmonitor1 and groupswrite

Can anyone help me on this?

Thanks in advance!

then your Bridge in OH2 KNX2 should be connecting to the knxd (via either tunnel or router type of IP connection)
The serial is being handled by knxd.

I changed my things file as below and it works now :slight_smile:

Bridge knx:ip:bridge [
    ipAddress="127.0.0.1",
    portNumber=3671,
    localIp="192.168.1.22",
    serialPort="/dev/ttyACM0", 
    type="TUNNEL",
    ignorelocalevents=true,
    readingPause=50, 
    responseTimeout=10, 
    readRetriesLimit=3, 
    autoReconnectPeriod=1,
    localSourceAddr="1.1.9"
   ] {
      Thing knx:device:bridge:generic {
       Type switch-control        : controlSwitch1        "Control Switch Left1"        [ ga="<0/0/51" ]
       Type switch-control        : controlSwitch2        "Control Switch Left2"        [ ga="<0/0/52" ]
       Type switch-control        : controlSwitch3        "Control Switch Left3"        [ ga="<0/0/53" ]
       Type switch-control        : controlSwitch4        "Control Switch Centre"        [ ga="<0/0/54" ]
       Type switch-control        : controlSwitch5        "Control Switch Others"        [ ga="<0/0/55" ]
             }
       }

1 Like

this is not needed. you can take it out :slight_smile:

@Dim Oh Okay. Thanks!

1 Like