Skip to content

OpenHAB

Fredrick Bäcker edited this page Nov 14, 2019 · 2 revisions

OpenHAB Configuration

To control the devices we need to setup a thing (MQTT), items (what to control) and sitemap (GUI control).

NOTE: MQTT Binding must be installed.

Thing

things/mqtt.things

NOTE: Seems like when changeing the things file OpenHAB doesn't update correctly. Restarting OpenHAB should do the trick.

Broker

The MQTT broker connects to MQTT and handling pub/sub.

Bridge  mqtt:broker:mybroker [
        host="127.0.0.1",
        secure=false,
        port=1883,
        clientid="OpenHAB"
    ]

    ... place things here ...

Bridge Things

A bridge thing is grouping of some kind. E.g. set of devices or an heatpump.

// Example Nexa RF button triggers
Thing topic nexa "Nexa Devices" {
    Channels:
        Type switch : outdoor1 "Outdoor 1" [
            commandTopic="broadlink/nexa/tmt-918/button1",
            stateTopic="broadlink/nexa/tmt-918/button1",
            retained=true,
            on="ON",
            off="OFF"
        ]
        Type switch : outdoor2 "Outdoor 2" [
            commandTopic="broadlink/nexa/tmt-918/button2",
            stateTopic="broadlink/nexa/tmt-918/button2",
            retained=true,
            on="ON",
            off="OFF"
        ]
}

// Example heater
Thing topic heater "Livingroom Heater" {
    Channels:
        Type string : mode "Mode" [
            commandTopic="broadlink/heater/livingroom/mode",
            stateTopic="broadlink/heater/livingroom/mode",
            retained=true
        ]
        Type number : temperature "Temperature" [
            commandTopic="broadlink/heater/livingroom/temperature",
            stateTopic="broadlink/heater/livingroom/temperature",
            retained=true
        ]
        Type switch : power "Power" [
            commandTopic="broadlink/heater/livingroom/power",
            stateTopic="broadlink/heater/livingroom/power"
        ]
}

Items

Connect an OpenHAB item to the Thing:Channel:Type

// Example Switch
Switch NexaOutdoor1 "Outdoor Porch" { channel="mqtt:topic:mybroker:nexa:outdoor1" }

// Example Heater
Switch HeaterPower "Heater Power" { channel="mqtt:topic:mybroker:heater:power" }
String HeaterMode "Heater Mode" { channel="mqtt:topic:mybroker:heater:mode" }
Number HeaterTemperature "Heater Temperature [%d]" { channel="mqtt:topic:mybroker:heater:temperature" }

Sitemap

Connect the things to sitemap to be able to gui control them.

// Example Switch
Switch item=NexaOutdoor1

// Example Heater
Frame label="Heater" {
    Switch item=HeaterPower label="On/Off"
    Selection item=HeaterMode mappings=[auto="Auto", cool="Cool", dry="Dry", fan="Fan", heat="Heat", low="Low"]
    Setpoint item=HeaterTemperature label="Temperature [%d]" minValue=16 maxValue=29 step=1
}
Clone this wiki locally