- Platform information:
- Hardware: Synology
- OS: Synology and Docker
- Java Runtime Environment: (whatever is included in the official openHAB Docker image)
- openHAB version: 2.5
I have some tasmota devices, working through the 2.5 MQTT binding, configured using a .things and a .items file. The setup itself works fine, I get state updates and can switch the plugs on and off through openHAB.
However, the power consumption of the plugs is reported via two MQTT topics and I want to bind those two topics to the same item. I tried several things, but can’t get it to work.
The topics in my case are:
plug02/tele/SENSOR = {"Time":"2020-01-14T11:56:16","ENERGY":{"TotalStartTime":"2019-12-13T00:08:28","Total":0.200,"Yesterday":0.017,"Today":0.114,"Period":13,"Power":160,"ApparentPower":179,"ReactivePower":80,"Factor":0.89,"Voltage":230,"Current":0.779}}
and
plug02/stat/STATUS8 = {"StatusSNS":{"Time":"2020-01-14T11:47:26","ENERGY":{"TotalStartTime":"2019-12-13T00:08:28","Total":0.177,"Yesterday":0.017,"Today":0.091,"Power":160,"ApparentPower":179,"ReactivePower":81,"Factor":0.89,"Voltage":230,"Current":0.779}}}
Minimal working mqtt.things:
Bridge mqtt:broker:mosquitto "Mosquitto MQTT Broker" [ host="homeserver", secure=false, clientID="openHAB_docker" ]
{
Thing topic tasmotaPlug02 "Plug 2" @ "Office" {
Channels:
Type switch : powerswitch "Steckdose 2" [stateTopic="plug02/stat/POWER", commandTopic="plug02/cmnd/POWER"]
Type number : power "Power" [stateTopic="plug02/tele/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
//Type number : power2 "Power" [stateTopic="plug02/stat/STATUS8", transformationPattern="JSONPATH:$.ENERGY.Power"]
}
}
Minimal working mqtt.items:
Switch plug02 "Plug 2" <plug> {channel="mqtt:topic:mosquitto:tasmotaPlug02:powerswitch"}
Number plug02_power "Power [%d W]" {channel="mqtt:topic:mosquitto:tasmotaPlug02:power"}
This working example links one of the MQTT topics to the item. I know I can create a second channel and a second item and use a rule to update the first item, but I would rather just configure it with the .things and/or items file.
I’ve tried adding a second topic to the channels, that did not work.
I also tried to create a separate channel for the second topic and added that channel to the existing item, but that did not work, either.
Is this even possible? And if so, what would be the correct syntax?
Or can I use a wildcard in the MQTT topic itself, so that the channel responds to both topics? If so, I don’t know how, the topic plug02/#
seems a bit broad to me. The payload is similar enough that the transformation pattern should work for both, though.
Thanks for your input!