mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-16 17:54:36 +00:00
OpenHAB 3.x exmples
This commit is contained in:
300
docs/openHAB.md
300
docs/openHAB.md
@@ -1,142 +1,220 @@
|
|||||||
:exclamation: There is a greate Step-By-Step guide from user HolgiHab at openhab community ([Step-By-Step Guide](
|
:exclamation: There is a greate Step-By-Step guide from user HolgiHab at openhab community ([Step-By-Step Guide](
|
||||||
https://community.openhab.org/t/step-by-step-guide-for-adding-tuya-bulbs-smart-life-to-oh2-using-tuya-mqtt-js-by-agentk/59371)). This guide is not only for light bulbs, but also applies to sockets. :exclamation:
|
https://community.openhab.org/t/step-by-step-guide-for-adding-tuya-bulbs-smart-life-to-oh2-using-tuya-mqtt-js-by-agentk/59371)). This guide is not only for light bulbs, but also applies to sockets. :exclamation:
|
||||||
|
|
||||||
## Example items for OpenHAB 1.x Bindings (still works with OH > 2.4 but only if legacy 1.x MQTT bindings are enabled)
|
## Example items for OpenHAB 3.x Bindings
|
||||||
### simple switch on/off
|
|
||||||
|
### Tuya Smart Thermostat Radiator Valve behind Tuya Gateway
|
||||||
|
|
||||||
|
### Things channels (configured via web):
|
||||||
|
|
||||||
|
#### Thermostat mode:
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
mode
|
||||||
```
|
```
|
||||||
|
|
||||||
Switch tuya_kitchen_coffeemachine_mqtt "Steckdose Kaffeemaschine" <socket> (<GROUPS>) ["Switchable"] {
|
State:
|
||||||
mqtt="<[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/state:state:default:.*],
|
```
|
||||||
>[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command/on:command:ON:true],
|
tuya/zgw1/1a24fkfffe6b4e24/dsp/4/state
|
||||||
>[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command/off:command:OFF:false]"
|
```
|
||||||
|
Example output: {"4":"auto"}
|
||||||
|
Possible values: auto/temp_auto/holiday/manual/comfort/eco/BOOST
|
||||||
|
|
||||||
|
|
||||||
|
Command:
|
||||||
|
```
|
||||||
|
tuya/zgw1/dps/command
|
||||||
|
```
|
||||||
|
|
||||||
|
Outgoing Value Format:
|
||||||
|
```
|
||||||
|
{"dps": 4, "set": "%s", "cid": "1a24fkfffe6b4e24"}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Temperature Setpoint
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
setpoint
|
||||||
|
```
|
||||||
|
|
||||||
|
State:
|
||||||
|
```
|
||||||
|
tuya/zgw1/1a24fkfffe6b4e24/dsp/2/state
|
||||||
|
```
|
||||||
|
Example output: {"2": 220}
|
||||||
|
|
||||||
|
Command:
|
||||||
|
```
|
||||||
|
tuya/zgw1/dps/command
|
||||||
|
```
|
||||||
|
|
||||||
|
Incoming Value Transformations:
|
||||||
|
```
|
||||||
|
JS:tuya-in.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Outgoing Value Transformation:
|
||||||
|
```
|
||||||
|
JS:tuya-out.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Outgoing Value Format:
|
||||||
|
```
|
||||||
|
{"dps": 2, "set": "%s", "cid": "1a24fkfffe6b4e24"}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Current Temperature
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
temperature
|
||||||
|
```
|
||||||
|
|
||||||
|
State:
|
||||||
|
```
|
||||||
|
tuya/zgw1/1a24fkfffe6b4e24/dsp/3/state
|
||||||
|
```
|
||||||
|
|
||||||
|
Incoming Value Transformations:
|
||||||
|
```
|
||||||
|
JS:tuya-in.js
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Valve percent
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
valve_percent
|
||||||
|
```
|
||||||
|
|
||||||
|
State:
|
||||||
|
```
|
||||||
|
tuya/zgw1/1a24fkfffe6b4e24/dsp/109/state
|
||||||
|
```
|
||||||
|
|
||||||
|
Command:
|
||||||
|
```
|
||||||
|
tuya/zgw1/dps/command
|
||||||
|
```
|
||||||
|
|
||||||
|
Outgoing Value Format:
|
||||||
|
```
|
||||||
|
{"dps": 109, "set": %s, "cid": "1a24fkfffe6b4e24"}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Transformations
|
||||||
|
tuya-in.js:
|
||||||
|
```
|
||||||
|
(function(i) {
|
||||||
|
return (i / 10)
|
||||||
|
})(input)
|
||||||
|
```
|
||||||
|
|
||||||
|
tuya-out.js:
|
||||||
|
```
|
||||||
|
(function(i) {
|
||||||
|
return (i * 10)
|
||||||
|
})(input)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### items/thermostat.items
|
||||||
|
|
||||||
|
```
|
||||||
|
String Radiator_Mode "Mode" <radiator> { channel="mqtt:topic:home:zgw1dev1:mode" }
|
||||||
|
Number Radiator_Setpoint "Temperature setpoint [%.1f °C]" <radiator> { channel="mqtt:topic:home:zgw1dev1:setpoint" }
|
||||||
|
Number Radiator_Temperature "Current temperature [%.1f °C]" <temperature> { channel="mqtt:topic:home:zgw1dev1:temperature" }
|
||||||
|
Number Radiator_Valve_Percent "Valve percent [%d %%]" { channel="mqtt:topic:home:zgw1dev1:valve_percent" }
|
||||||
|
```
|
||||||
|
|
||||||
|
### sitemaps/home.sitemap
|
||||||
|
|
||||||
|
```
|
||||||
|
Frame label="Heating" {
|
||||||
|
Setpoint item=Radiator_Setpoint minValue=15 maxValue=30 step=0.5
|
||||||
|
Selection item=Radiator_Mode mappings=[auto='Auto', temp_auto='Auto temp', manual='Manual', comfort='Comfort']
|
||||||
|
Text item=Radiator_Setpoint
|
||||||
|
Text item=Radiator_Temperature
|
||||||
|
Text item=Radiator_Valve_Percent
|
||||||
}
|
}
|
||||||
|
|
||||||
Switch tuya_livingroom_ledstrip_tv "LED Regal" <lightbulb> (<GROUPS>) ["Lighting"] {
|
|
||||||
mqtt="<[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/state:state:default:.*],
|
|
||||||
>[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command/on:command:ON:true],
|
|
||||||
>[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command/off:command:OFF:false]"
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### change color of lightbulb
|
|
||||||
|
|
||||||
|
|
||||||
|
### Simple on/off switch with power measurement capability
|
||||||
|
|
||||||
|
### Things channels (configured via web):
|
||||||
|
|
||||||
|
#### Power switch
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
power
|
||||||
```
|
```
|
||||||
|
|
||||||
# .items
|
State:
|
||||||
Group gTuyaLivingColor "Tuya color group" <lightbulb>
|
```
|
||||||
Color tuya_livingroom_colorpicker "Stehlampe farbe" (LivingDining)
|
tuya/tuya_device_1/state
|
||||||
|
```
|
||||||
String tuya_livingroom_ledstrip_tv_color "Set color [%s]" (gTuyaLivingColor, LivingDining) {
|
Example output: {"4":"auto"}
|
||||||
mqtt=">[broker:tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/color:command:*:default]"
|
Possible values: auto/temp_auto/holiday/manual/comfort/eco/BOOST
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# .rules
|
|
||||||
import org.openhab.core.library.types.HSBType;
|
|
||||||
|
|
||||||
rule "Set HSB value of item RGBLed to RGB color value"
|
|
||||||
when
|
|
||||||
Item tuya_livingroom_colorpicker received command
|
|
||||||
then
|
|
||||||
var appName = "Colorpicker.livingroom"
|
|
||||||
var color = receivedCommand.toString;
|
|
||||||
|
|
||||||
// get all colors and send it via mqtt if light ist enabled
|
|
||||||
gTuyaLivingColor.members.forEach[ i |
|
|
||||||
var name = i.name;
|
|
||||||
var stateName = name.toString.split("_color").get(0);
|
|
||||||
var stateItem = gTuyaLights.allMembers.filter [ conf | conf.name.contains(stateName.toString) ].head;
|
|
||||||
|
|
||||||
if(stateItem.state == ON){
|
|
||||||
logInfo(appName, name + " change to color: " + color);
|
|
||||||
i.sendCommand(color);
|
|
||||||
Thread::sleep(400);
|
|
||||||
}
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
|
Command:
|
||||||
|
```
|
||||||
|
tuya/tuya_device_1/command
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example items for OpenHAB 2.4 Bindings
|
Custom On/Open Value:
|
||||||
### simple switch on/off
|
```
|
||||||
|
ON
|
||||||
With OpenHAB 2.X MQTT bindings you can add devices using a generic MQTT Thing via PaperUI or
|
|
||||||
configuration files. For PaperUI simply at the generic MQTT Thing and set the state and
|
|
||||||
command topics as follows:
|
|
||||||
```
|
```
|
||||||
|
|
||||||
tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/state
|
Custom Off/Closed Value:
|
||||||
|
```
|
||||||
tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command
|
OFF
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you prefer using configuration files vs PaperUI, it should look something like this:
|
#### Power consumption watts
|
||||||
See also OpenHAB 2.X MQTT binding [documentation](https://www.openhab.org/v2.4/addons/bindings/mqtt.generic/)
|
Channel identifier:
|
||||||
|
```
|
||||||
|
w
|
||||||
```
|
```
|
||||||
|
|
||||||
Bridge mqtt:broker:myUnsecureBroker [ host="localhost", secure=false ]
|
State:
|
||||||
{
|
```
|
||||||
|
tuya/tuya_device_1/dps/19/state
|
||||||
Thing mqtt:topic:myCustomMQTT {
|
|
||||||
Channels:
|
|
||||||
Type switch : tuya_kitchen_coffeemachine_mqtt_channel "Kitchen Coffee Machine MQTT Channel" [
|
|
||||||
stateTopic="tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/state",
|
|
||||||
commandTopic="tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command",
|
|
||||||
|
|
||||||
// optional custom mqtt-payloads for ON and OFF
|
|
||||||
on="{ \"dps\": 1, \"set\": true }",
|
|
||||||
off="0"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# *.item Example
|
|
||||||
Switch tuya_kitchen_coffeemachine_mqtt "Kitchen Coffee Machine Switch" <socket> (gKitchen, gTuya) ["Switchable"] {
|
|
||||||
channel="mqtt:topic:myUnsecureBroker:myCustomMQTT:tuya_kitchen_coffeemachine_mqtt_channel"
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For one RGB bulb you would need a separate channel with the command topic set to
|
Incoming Value Transformations:
|
||||||
`tuya/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/color` and link that to your color item.
|
JS:tuya-energy.js
|
||||||
|
|
||||||
|
#### Power consumption volts
|
||||||
|
Channel identifier:
|
||||||
|
```
|
||||||
|
v
|
||||||
```
|
```
|
||||||
|
|
||||||
Bridge mqtt:broker:myUnsecureBroker [ host="localhost", secure=false ]
|
State:
|
||||||
{
|
```
|
||||||
Thing mqtt:topic:myCustomMQTT {
|
tuya/tuya_device_1/dps/20/state
|
||||||
Channels:
|
|
||||||
Type colorHSB : livingroom_floorlamp_1_color "Livingroom floorlamp color MQTT Channel" [
|
|
||||||
stateTopic="tuya/05200399bcddc2e02ec9/b58cf92e8bc5c899/192.168.178.49/state",
|
|
||||||
commandTopic="tuya/05200399bcddc2e02ec9/b58cf92e8bc5c899/192.168.178.49/color"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# *.item Example
|
|
||||||
Color tuya_livingroom_colorpicker "Floorlamp colorpicker" (gLivingroom){
|
|
||||||
channel="mqtt:topic:myUnsecureBroker:myCustomMQTT:livingroom_floorlamp_1_color"
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Basic UI sitemap
|
Incoming Value Transformations:
|
||||||
|
JS:tuya-energy.js
|
||||||
|
|
||||||
|
### transform/tuya-energy.js
|
||||||
|
```
|
||||||
|
(function(i) {
|
||||||
|
return Math.ceil(i / 10)
|
||||||
|
})(input)
|
||||||
```
|
```
|
||||||
|
|
||||||
Switch item=tuya_kitchen_coffeemachine_mqtt
|
### items/socket.items
|
||||||
|
|
||||||
# turn the color bulb off or on
|
Switch Socket_Power "Socket" { channel="mqtt:topic:socket:power" }
|
||||||
Switch item=tuya_livingroom_colorpicker label="RGB lamp [%s]"
|
Number Socket_W "Power (W)" { channel="mqtt:topic:socket:w" }
|
||||||
|
Number Socket_Vt "Power (V) [%s]" { channel="mqtt:topic:socket:v" }
|
||||||
|
|
||||||
# pick the color level to send to the color bulb via MQTT color Channel
|
### sitemaps/home.sitempa
|
||||||
Slider item=tuya_livingroom_colorpicker label="RGB lamp level [%s]" minValue=0 maxValue=100 step=1
|
|
||||||
|
|
||||||
# color picked and sent via MQTT Color channel
|
Switch item=Socket_Power
|
||||||
Colorpicker item=tuya_livingroom_colorpicker label="RGB lamp color [%s]" icon="colorpicker" sendFrequency=30000
|
Text item=Socket_W
|
||||||
|
Text item=Socket_Vt
|
||||||
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user