Second channel returns NULL

  • Platform information:
    • RASPI 4
    • Rasberian
    • Java Runtime Environment: 11
    • openHAB version: 3
  • Issue of the topic: Sencond channel of a tasmota switch show NULL

I defined a thing with two channels using mqtt bindings. The first channel provides the correct value, the second shows always NULL.
What did I wrong ?

UID: mqtt:topic:35b9925914
label: GS-55 Total
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:minion_mqtt
channels:

  • id: gs_55_sensor_total
    channelTypeUID: mqtt:number
    label: gs_55_sensor_total
    description: “”
    configuration:
    commandTopic: ‘“cmnd/gosound_switches/gosound-55/STATUS 8”’
    formatBeforePublish: “%.4f”
    stateTopic: stat/gosound_switches/gosound-55/STATUS8
    transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Total
  • id: gs_55_sensor_today
    channelTypeUID: mqtt:number
    label: gs_55_sensor_today
    description: “”
    configuration:
    commandTopic: ‘“cmnd/gosound_switches/gosound-55/STATUS 8”’
    stateTopic: stat/gosound_switches/gosound-55/STATUS8
    transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Total

Without having such a device we would at least need an example of the full Status8 message you are receiving.

{“StatusSNS”:{“Time”:“2021-07-14T08:14:20”,“ENERGY”:{“TotalStartTime”:“2021-07-03T14:29:02”,“Total”:0.659,“Yesterday”:0.054,“Today”:0.001,“Power”:4,“ApparentPower”:7,“ReactivePower”:6,“Factor”:0.59,“Voltage”:220,“Current”:0.034}}}

Did you by chance change the type manually in the YAML? This won’t work, and you have to delete and recreate the Channel.

This shouldn’t be the issue but both your Channels are extracting Total

1 Like

No, I didn’t change the YAML
Yes, for testing purposes I configured exact the same Pattern, that’s why I wonder why the first work, the second not. I also tired with Pattern “JSONPATH:$.StatusSNS.ENERGY.Today” and got the same result: NULL

Could you reformat your first post and copy/paste your configuration in-between code fences?

Have you linked both Channels to distinct Items?

Yes both have dedicated items

UID: mqtt:topic:35b9925914
label: GS-55 Total
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:minion_mqtt
channels:
    id: gs_55_sensor_total
    channelTypeUID: mqtt:number
    label: gs_55_sensor_total
    description: “”
    configuration:
    commandTopic: ‘“cmnd/gosound_switches/gosound-55/STATUS 8”’
    formatBeforePublish: “%.4f”
    stateTopic: stat/gosound_switches/gosound-55/STATUS8
    transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Total
    id: gs_55_sensor_today
    channelTypeUID: mqtt:number
    label: gs_55_sensor_today
    description: “”
    configuration:
    commandTopic: ‘“cmnd/gosound_switches/gosound-55/STATUS 8”’
    stateTopic: stat/gosound_switches/gosound-55/STATUS8
    transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Total

formatBeforePublish: “%.4f”
Missing on second channel maybe?

makes no difference, either the result is handled as string or as float
 I tried both

formatbeforepublish has nothing to do with incoming state topics.

Make sure you have not applied profile to your channel-Item links by accident.

Bindings are not always that clever about actioning in-flight edits. After all this editing, when you’ve got your best guess set up, try a restart.

I tried to restart and suddenly I get the value, BUT
when I change something in the second channels it will not be shown neither the value nor the unit, even when I restart
it looks now:

label: GS-55 Total
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:minion_mqtt
channels:
  - id: gs_55_sensor_total
    channelTypeUID: mqtt:number
    label: gs_55_sensor_total
    description: ""
    configuration:
      commandTopic: '"cmnd/gosound_switches/gosound-55/STATUS 8"'
      unit: kWh
      formatBeforePublish: "%.4f"
      stateTopic: stat/gosound_switches/gosound-55/STATUS8
      transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Total
  - id: gs_55_sensor_today
    channelTypeUID: mqtt:number
    label: gs_55_sensor_today
    description: ""
    configuration:
      commandTopic: '"cmnd/gosound_switches/gosound-55/STATUS 8"'
      unit: kWh
      formatBeforePublish: "%.4f"
      stateTopic: stat/gosound_switches/gosound-55/STATUS8
      transformationPattern: JSONPATH:$.StatusSNS.ENERGY.Today

Good.

What type of Item are you linking to? You may not be aware that MQTT channel parameter unit:kWh is currently not applied to incoming data (that is being worked on), only to outgoing messages.

So the change you made is suspect. That would look to be your JSONPATH. What does your incoming message payload look like?

The incoming message is:
{“StatusSNS”:{“Time”:“2021-07-14T08:14:20”,“ENERGY”:{“TotalStartTime”:“2021-07-03T14:29:02”,“Total”:0.659,“Yesterday”:0.054,“Today”:0.001,“Power”:4,“ApparentPower”:7,“ReactivePower”:6,“Factor”:0.59,“Voltage”:220,“Current”:0.034}}}

Looks fine to me. You know this works in general now, and it’s either a mistake in config or Item linking, or your edits not yet taken into account.

Is possible to export items and channels as json/yaml objetcs, so I can compare them?
or copy an item into an other ?

See the tool API explorer for JSON representation.

Found the reason:

JSONPATH:$.StatusSNS.ENERGY.Today must be trigger manually

JSONPATH:$.ENERGY.Today is triggered periodically by the device

Did you by chance change the type manually in the YAML? This won’t work, and you have to delete and recreate the Channel.

I just wanted to let you know that I found this post searching deeply on Google for why SOME of my MQTT Thing channels were coming up NULL despite being properly coded in the YAML. You were right, you can’t edit the “Code” version of the Thing, you need to use the UI to create/edit all the Channels. Is there a bug filed on this, as you seemed to know it was an issue so perhaps there is? It’s not urgent to fix, but would be good to document as errata.

Why would you think it a bug for an unsupported method not to work?

Or are you running into this issue

I guess the point is that @jschmidt hasn’t seen it written anywhere that it is unsupported. And the fact that the text within the Code tab is fully editable and save-able would suggest that it is supported.