-
Notifications
You must be signed in to change notification settings - Fork 14
OpenHAB
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.
things/mqtt.things
NOTE: Seems like when changeing the things file OpenHAB doesn't update correctly. Restarting OpenHAB should do the trick.
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 ...
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"
]
}
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" }
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
}
Looking at old example of an items file the structure did follow setting files in device folders. If you followed this you don't need to move your files.
Note that you also do not need to re-record any of the actions from v1.
// OLD v1 of MQTT binding and broadlink v1
// items/gui.items
Switch OutdoorLight1 "Outdoor Porch" {mqtt=">[mqtt:broadlink/switches/outdoor/garden1/on:command:ON:play],>[mqtt:broadlink/switches/outdoor/garden1/off:command:OFF:play]"}
This will result in the new MQTT 2 binding:
// things/mqtt.things
Bridge mqtt:broker:mybroker [
host="127.0.0.1",
secure=false,
port=1883,
clientid="OpenHAB"
]
Thing topic nexa "Nexa Devices" {
Channels:
Type switch : garden1 "Garden 1" [
commandTopic="broadlink/switches/outdoor/garden1",
stateTopic="broadlink/switches/outdoor/garden1",
on="ON",
off="OFF"
]
}
// items/gui.items
Switch NexaOutdoor1 "Outdoor Garden" { channel="mqtt:topic:mybroker:nexa:garden1" }