[SOLVED] Bind two channels to one item via config files?

  • 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!

In general, openHAB allows multiple channels linked to one Item. It’s not always sensible of course, depending on the nature of the channels.

What are you hoping to achieve there? There is no way to sum, prioritize, or even select the maximum of the competing values. The Item will simply reflect the state of the last channel update, whichever it was.

Guessing from your raw data examples though, that is what you want. Duplicate data can appear in either of two topic formats, you want to use whichever arrived most recently.

C’mon :wink: more detail?

I’d do that first, to confirm your topic and transformation details are correct. Work on combining alongside that.

In fact for testing, I’d set up three Items, one for each individual channel and one for the combo, so you can see the sequence of events.

I am a little concerned about what happens when channel A updates and channel B doesn’t. That should be fine, nothing should happen to B. But I have seen MQTT binding playing oddball here before and overriding Item changes with remembered data. Definitely would mess up in 2.4 - I am not sure about 2.5.

You could try postUpdating an Item from REST API and see if the channel forces it back, even in the absence of an MQTT message.

It looks I was wrong with my assumption that the JSON transformation would work for both topics :roll_eyes:
I now got it working with this configuration:

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 : powerTele   "Power"           [stateTopic="plug02/tele/SENSOR",  transformationPattern="JSONPATH:$.ENERGY.Power"]
            Type number : powerStat   "Power"           [stateTopic="plug02/stat/STATUS8", transformationPattern="JSONPATH:$.StatusSNS.ENERGY.Power"]
    }
}

mgtt.items:

Switch  plug02        "Plug 2"         <plug>   {channel="mqtt:topic:mosquitto:tasmotaPlug02:powerswitch", alexa="Switchable"}
Number  plug02_power  "Power [%d W]"            {channel="mqtt:topic:mosquitto:tasmotaPlug02:powerStat, mqtt:topic:mosquitto:tasmotaPlug02:powerTele"}

plug02_power is now updated from both channels :slight_smile:

1 Like