How create channels for multiple sensor on Tasmota

  • Platform information:
    • Hardware: RPi 4 4GB
    • OS: openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 3.3

I’ve got few DS18B20 temperature sensors connected to nodemcu with Tasmota onboard.
When I disconnected one of them my items get mess so how I can stick it to right items?
Here it is log from tasmota:

 19:55:46 MQT: tele/tasmota-nodemcu/SENSOR = {"Time":"2022-12-26T19:55:46","DS18B20-1":{"Id":"011937C96546","Temperature":58.6},"DS18B20-2":{"Id":"3C01B556CD9B","Temperature":52.6},"DS18B20-3":{"Id":"3CFFB5560039","Temperature":26.2},"SI7021-04":{"Temperature":null,"Humidity":null,"DewPoint":0.0},"SI7021-05":{"Temperature":null,"Humidity":null,"DewPoint":0.0},"BME680":{"Temperature":20.8,"Humidity":31.7,"DewPoint":3.3,"Pressure":979.7,"Gas":1229.43},"SR04":{"Distance":61.737},"PressureUnit":"hPa","TempUnit":"C"} 

My things look like that:

  • id: ds18b201temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-1.Temperature
  • id: ds18b202id
    channelTypeUID: mqtt:string
    label: Sensor id
    description: null
    configuration:
    retained: false
    postCommand: false
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-2.Id
  • id: ds18b202temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-2.Temperature
  • id: ds18b203id
    channelTypeUID: mqtt:string
    label: Sensor id
    description: null
    configuration:
    retained: false
    postCommand: false
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-3.Id
  • id: ds18b203temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-3.Temperature
  • id: ds18b204id
    channelTypeUID: mqtt:string
    label: Sensor id
    description: null
    configuration:
    retained: false
    postCommand: false
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-4.Id
  • id: ds18b204temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-4.Temperature
  • id: ds18b205id
    channelTypeUID: mqtt:string
    label: Sensor id
    description: null
    configuration:
    retained: false
    postCommand: false
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-5.Id
  • id: ds18b205temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-5.Temperature
  • id: ds18b206id
    channelTypeUID: mqtt:string
    label: Sensor id
    description: null
    configuration:
    retained: false
    postCommand: false
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-6.Id
  • id: ds18b206temp
    channelTypeUID: mqtt:number
    label: Sensor temp
    description: null
    configuration:
    retained: false
    postCommand: false
    step: 1
    formatBeforePublish: “%s”
    stateTopic: tele/tasmota-nodemcu/SENSOR
    transformationPattern: JSONPATH:$.DS18B20-6.Temperature

For example I disconnect sensor called DS18B20-3 which is linked to item TEMPERATURE3 then DS18B20-4 is going to be new DS18B20-3 and links to TEMPERATURE3 but for me it should be still TEMPERATURE4.

Is there any solution ?

I have a NodeMCU clone flashed with Tasmota, and two DS18B20 sensors attached. They are addressed individually by their unique Id - this never changes, irrespective of removals or additions.

Here is the JSON from the tele/tTank/SENSOR topic

{
  "Time": "2022-12-26T21:48:02",
  "DS18B20-1": {
    "Id": "062141D4EF92",
    "Temperature": 39.8
  },
  "DS18B20-2": {
    "Id": "0621425FC1D8",
    "Temperature": 16
  },
  "TempUnit": "C"
}

Here is the openHAB Thing

UID: mqtt:topic:tank
label: Tank Sensor
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
channels:
  - id: temperature_top
    channelTypeUID: mqtt:number
    label: Temperature top
    description: null
    configuration:
      stateTopic: tele/tTank/SENSOR
      transformationPattern: JSONPATH:$..[?(@.Id=="062141D4EF92")].Temperature
  - id: temperature_bottom
    channelTypeUID: mqtt:number
    label: Temperature top
    description: null
    configuration:
      stateTopic: tele/tTank/SENSOR
      transformationPattern: JSONPATH:$..[?(@.Id=="0621425FC1D8")].Temperature
1 Like

Thanks. This transformation is solution

transformationPattern: JSONPATH:$..[?(@.Id=="062141D4EF92")].Temperature