OpenMQTTGateway Autodiscovery with OpenHAB following Home Assistant convention

Could you share the messages of your sensor you have into your mqtt broker homeassistant/sensor , like below

{"stat_t":"+/+/BTtoMQTT/112233445566","dev_cla":"temperature","unit_of_meas":"°C","name":"LYWSD03MMC_ATC-tempc","uniq_id":"112233445566-tempc","val_tpl":"{{ value_json.tempc | is_defined }}","state_class":"measurement","device":{"identifiers":["112233445566"],"connections":[["mac","112233445566"]],"manufacturer":"Xiaomi","model":"LYWSD03MMC_ATC","name":"LYWSD03MMC-800021","via_device":"OMG"}}

Could you check if you see the messages coming from the sensor in the broker with MQTT Explorer ?

If i add the sensor as Thing i get the following message in the openhab Logfile:

2023-01-12 09:13:06.696 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channel 'A4C138E18ECF_2Dbatt#sensor', because channel type 'mqtt:A4C138E18ECF_2Dbatt_sensor' could not be found.

2023-01-12 09:13:06.700 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channel 'A4C138E18ECF_2Dvolt#sensor', because channel type 'mqtt:A4C138E18ECF_2Dvolt_sensor' could not be found.

2023-01-12 09:13:06.704 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channel 'A4C138E18ECF_2Dtemp#sensor', because channel type 'mqtt:A4C138E18ECF_2Dtemp_sensor' could not be found.

2023-01-12 09:13:06.707 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channel 'A4C138E18ECF_2Dhum#sensor', because channel type 'mqtt:A4C138E18ECF_2Dhum_sensor' could not be found.

2023-01-12 09:13:06.710 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channels for channel group 'A4C138E18ECF_2Dbatt' for thing type 'mqtt:homeassistant_A4C138E18ECF:d8bc7a043f:A4C138E18ECF', because channel group type 'mqtt:A4C138E18ECF_2Dbatt' could not be found.

2023-01-12 09:13:06.712 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channels for channel group 'A4C138E18ECF_2Dvolt' for thing type 'mqtt:homeassistant_A4C138E18ECF:d8bc7a043f:A4C138E18ECF', because channel group type 'mqtt:A4C138E18ECF_2Dvolt' could not be found.

2023-01-12 09:13:06.715 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channels for channel group 'A4C138E18ECF_2Dtemp' for thing type 'mqtt:homeassistant_A4C138E18ECF:d8bc7a043f:A4C138E18ECF', because channel group type 'mqtt:A4C138E18ECF_2Dtemp' could not be found.

2023-01-12 09:13:06.717 [WARN ] [re.thing.internal.ThingFactoryHelper] - Could not create channels for channel group 'A4C138E18ECF_2Dhum' for thing type 'mqtt:homeassistant_A4C138E18ECF:d8bc7a043f:A4C138E18ECF', because channel group type 'mqtt:A4C138E18ECF_2Dhum' could not be found.

In mqtt broker homeassistant/sensor it looks like:

{
  "stat_t": "+/+/BTtoMQTT/A4C138BDE967",
  "dev_cla": "temperature",
  "unit_of_meas": "°C",
  "name": "temp",
  "uniq_id": "A4C138BDE967-temp",
  "val_tpl": "{{ value_json.tempc }}",
  "state_class": "measurement",
  "device": {
    "identifiers": [
      "A4C138BDE967"
    ],
    "connections": [
      [
        "mac",
        "A4C138BDE967"
      ]
    ],
    "manufacturer": "Xiaomi",
    "model": "LYWSD03MMC",
    "name": "LYWSD03MMC-BDE967",
    "via_device": "OpenMQTTGateway_ESP32_BLE_OH"
  }
}

homeassistant/sensor/A4C138BDE967-temp/config

And under this do you see the data coming? (You need to prefix it by home/<gateway_name>

there is only this:

{
  "id": "A4:C1:38:BD:E9:67",
  "mac_type": 0,
  "name": "LYWSD03MMC",
  "rssi": -88,
  "servicedata": "30585b05e267e9bd38c1a408",
  "rssi": -87,
  "servicedata": "30585b05e467e9bd38c1a408",
  "servicedatauuid": "0xfe95"
}

For more regular measurement, I advise to flash the LYWSD03MMC with ATC or PVVX custom firmware, it should take less than 5 minutes and can be done over the air.

The stock LYWSD03MMC requires a bind key to read the data or a BLE connection that consumes battery life.

I have flashed all my sensors and now the warnings in openhab are gone.

all of them are now online…

1 Like

ANd you see the sensor values I suppose ?

Yes I can:

Topic: home/TheengsGateway/BTtoMQTT/A4C13834A4ECQoS: 0
{"name": "ATC_34A4EC", "id": "A4:C1:38:34:A4:EC", "rssi": -64, "brand": "Xiaomi", "model": "LYWSD03MMC", "model_id": "LYWSD03MMC_PVVX", "tempc": 21.06, "tempf": 69.908, "hum": 57.65, "batt": 0, "volt": 2.154}

All my LYWSD03MMC uses ATC PVVX

I created “manualy” thing and then it works without errors

2023-01-13 15:54:31.636 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'aaa_term_xiaomi_aaa_temp' changed from 21.09 to 21.04

==> /var/log/openhab/openhab.log <==

2023-01-13 15:54:31.643 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.batt | is_defined

2023-01-13 15:54:31.657 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.tempc | is_defined

2023-01-13 15:54:31.669 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.hum | is_defined

2023-01-13 15:54:31.678 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt | is_defined

Yes it works fine now. I see values.

1 Like

Please try the last Docker version once built:

Or replace the parameter
HAAS_DISCOVERY: false
by
HASS_DISCOVERY: false

1 Like

Thank you very much!
Now it’s working great!

1 Like

This seems to be still an issue in the actual version 1.5 of OpenMQTTGateway binary liligo-rtl_433. It would be great to have the Autodiscovery running for OpenHAB.

We could add its activation as an mqtt command if suitable for you

This would be a great option to have in the prebuild binary. I tried several steps to compile it with the option, but could not get it running on the board.

Regards Christoph

You can build your binary with gitpod if you like

Here is an environment that should work with OpenHAB, paste it into the environments.ini, save

[env:lilygo-rtl_433-oh]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ssd1306}
  ${libraries.rtl_433_ESP}
build_flags =
  ${com-esp.build_flags}
  '-DOpenHABDiscovery=true'
; *** OpenMQTTGateway Config ***
  ;'-UZmqttDiscovery'          ; disables MQTT Discovery
  '-DvalueAsATopic=true'    ; MQTT topic includes model and device
  '-DGateway_Name="OpenMQTTGateway_lilygo_rtl_433_ESP"'
; *** OpenMQTTGateway Modules ***
  '-DZgatewayRTL_433="rtl_433"'
  '-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
  '-DZdisplaySSD1306="LilyGo_SSD1306"'

And launch the following command in the terminal:
platformio run -e lilygo-rtl_433-oh

Wait one minute and you should have the binaries ready:

I tried it several times with a my_env.ini that contained the -DOpenHABDiscovery=true as the only difference. The compilation ran without errors, but I couldn’t upload the binary from platformio, because no ports were shown in my two Lenovo laptops.
Later I tried to upload the binaries with esptool from Linux, but got an error. With the expressif framework on Windows 10 I could upload successfully, but the software did not start, no Wifi network appeared on my mobile.

I compiled the environment lilygo-rtl_433-oh, you provided and indeed its running now with OH autodiscovery.
I used this upload tool:


and got these results:

After a reboot of the device ist was running and I could configure my SSID and MQTT broker.
Before I had the additional boot_app0.bin selected. I found it in other sources for uploading to ESP32. Could this have been wrong?
This was my environment in my_env.ini:

[platformio]
default_envs = lilygo-rtl_433

[env:lilygo-rtl_433-openhab]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ssd1306}
  ${libraries.rtl_433_ESP}
build_flags =
  ${com-esp.build_flags}
; *** OpenMQTTGateway Config ***
  ;'-UZmqttDiscovery'          ; disables MQTT Discovery
  '-DvalueAsATopic=true'    ; MQTT topic includes model and device
  '-DOpenHABDiscovery=true'
  '-DGateway_Name="OpenMQTTGateway_lilygo_rtl_433_ESP_OH"'
; *** OpenMQTTGateway Modules ***
  '-DZgatewayRTL_433="rtl_433"'
  '-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
  '-DZdisplaySSD1306="LilyGo_SSD1306"'
;  '-DLOG_TO_OLED=true'         ; Enable log to OLED
;  '-DJSON_TO_OLED=true'
;  '-DLOG_LEVEL_OLED=LOG_LEVEL_NOTICE'
;  '-DDISPLAY_IDLE_LOGO=false'
;  '-DDISPLAY_BRIGHTNESS=80'
;  '-DDISPLAY_METRIC=false'
custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib, openHAB discovery enabled
custom_hardware = ESP32 LILYGO LoRa32 V2.1

Where is the wrong point?

Thanks a lot for your help!
Regards Christoph

Try to take the one in the link (Option 2) Upload ready-to-go binaries | OpenMQTTGateway v1.7.0. It would avoid this uncertainty.

Also once the wifi and mqtt credentials are configured in the web portal what does the board OLED or a serial monitor says ?