OpenMQTTGateway Autodiscovery with OpenHAB following Home Assistant convention

I have modified the code of OpenMQTTGateway to make it compatible with Autodiscovery:

I have done some tests but I would like to have some feedbacks if some OpenHAB users are interested on testing it?

This function rely on Home Assistant Autodiscovery topics.

hey @1technophile,

If you need any more testing, Iā€™m trying to get OMG0.9.6 to send values from a MiFlora sensor using a M5StickC.

The M5 is auto-discovered, and I think the MiFlora is discovered as well, but it shows ā€˜UNKNOWNā€™ state as a thing, and linked items get no values. I think it has to do with the default MQTT paths it created them with, but Iā€™m a little unsure about how it is supposed to work.

Looking forward to using this for IR emitting and moisture sensing!

Hi Jason,

Are you able to get the value on the mqtt broker as a first check?
If yes could you post how the think looks like in OpenHAB?

I wanted to go back to square one so I removed the things and flashed a different M5stickC.

I configured wifi and MQTT server, and left the default topic as ā€˜homeā€™

when it came up I had two discovered ā€˜thingsā€™ in my inbox:

When I add the omg_xavier item, I get lots of errors in the logs:

2021-06-09 18:06:12.213 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:homeassistant_5002918EE2DC:e57442e4:5002918EE2DC' changed from UNINITIALIZED to INITIALIZING
2021-06-09 18:06:12.220 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:homeassistant_5002918EE2DC:e57442e4:5002918EE2DC' changed from INITIALIZING to UNKNOWN
==> /var/log/openhab/openhab.log <==
2021-06-09 18:06:14.268 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online
2021-06-09 18:06:14.271 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online
2021-06-09 18:06:14.274 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online
2021-06-09 18:06:14.335 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online
2021-06-09 18:06:14.336 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online
2021-06-09 18:06:14.337 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'online' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.online

Sorry for the consecutive repliesā€¦ but seems easier this way to a semi-private threadā€¦

I am seeing MQTT transmission under home/# and homeassistant/#ā€¦

all the homeassistant messages are retained

OMG config

UID: mqtt:homeassistant_********2DC:******e4:********2DC
label: omg_xavier
thingTypeUID: mqtt:homeassistant_********2DC
configuration:
  topics:
    - binary_sensor/********2DCconnectivity
    - sensor/********2DCinterval
    - switch/********2DCforce_scan
    - switch/********2DChasspresence
    - sensor/********2DCm5vinvoltage
    - switch/********2DCbleconnect
    - sensor/********2DCm5batcurrent
    - switch/********2DCrestart
    - switch/********2DClowpowermode
    - binary_sensor/********2DCGPIOInput
    - sensor/********2DCm5batvoltage
    - switch/********2DCerase
    - switch/********2DCdiscovery
    - sensor/********2DCfreemem
    - sensor/********2DCuptime
    - switch/********2DConly_sensors
    - sensor/********2DCip
    - sensor/********2DCscanbcnct
    - sensor/********2DCgatewayIR
    - sensor/********2DCm5vincurrent
    - sensor/********2DClowpowermode
    - sensor/********2DCrssi
  basetopic: homeassistant
bridgeUID: mqtt:broker:******e4


Could you share the version of OpenHAB used please?

On the broker side (if you check with MQTT explorer) do you see values coming?

3.1.0M5ā€¦

and yes, seeing values:

{"id":"C4:**:**:**:**:F2","name":"Flower care","rssi":-70,"model":"HHC******HHCC","tempc":27.1,"tempf":80.78}

I need to update my OpenHAB to 3.1 (Iā€™m still with a 2.Xā€¦)

No worriesā€¦ I know I could define the things and items manually, but I was intrigued that discovery picked things up and wanted to ā€˜make things easyā€™.

Cheers!

But any thoughts on these errors?

2021-06-09 20:54:10.319 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.lux | is_defined
2021-06-09 20:54:10.333 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.fer | is_defined
2021-06-09 20:54:10.342 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.moi | is_defined
2021-06-09 20:54:10.358 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.tempc | is_defined

same problem here. Values of autodiscovered items are not updated. I have similar error message like you:

12:40:23.273 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.hum | is_defined
12:40:23.275 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.tempc | is_defined
12:40:23.285 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.batt | is_defined

Furthermore, the status of the Thing remains to unknown and doesnā€™t go to online.

For me it looks like things that contain is_defined in val_tpl doesnā€™t work.
For example, this item does not work for me:

{{ value_json.hum | is_defined }}

full version:

{"stat_t":"+/+/BTtoMQTT/12345678910A","name":"CLEARGRASSTRH-hum","uniq_id":"12345678910A-CLEARGRASSTRH-hum","dev_cla":"humidity","val_tpl":"{{ value_json.hum | is_defined }}","unit_of_meas":"%","device":{"connections":[["mac","12345678910A"]],"identifiers":["12345678910A"],"manufacturer":"ClearGrass","model":"CGG1","name":"CLEARGRASSTRH","via_device":"OpenMQTTGateway_ESP32_BLE"}}

On the other side an item with just:

{{ value_json.rssi }}

works fine for me

In the discovery configuration of OMG you have to set this to true for Openhab

This way the is_defined is removed.

1 Like

Hello!
Iā€™ve got TheengsGateway in Docker and get the same error . Is there any cure for this?

2023-01-10 22:19:21.551 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt | is_defined

2023-01-10 22:19:21.562 [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-10 22:19:21.568 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.batt | is_defined

You can either use the solution above, or use esp32dev-ble-openhab from the web upload page:

But I use TheengsGateway in Docker

  theengsgateway:
    image: maretodoric/theengsgateway-arm-v7:latest
    container_name: theengsgateway
    network_mode: host
    environment:
      MQTT_HOST: xxx
      MQTT_USERNAME: xxx
      MQTT_PASSWORD: xxx
      MQTT_PUB_TOPIC: home/TheengsGateway/BTtoMQTT
      MQTT_SUB_TOPIC: home/TheengsGateway/commands
      PUBLISH_ALL: true
      TIME_BETWEEN: 60
      SCAN_TIME: 60
      LOG_LEVEL: DEBUG
      HAAS_DISCOVERY: false
      DISCOVERY: true
      DISCOVERY_TOPIC: homeassistant/sensor
      DISCOVERY_DEVICE_NAME: TheengsGateway
      DISCOVERY_FILTER: "[IBEACON,GAEN,MS-CDP]"
      SCANNING_MODE: active
      ADAPTER: hci0
    volumes:
      - /var/run/dbus:/var/run/dbus

I still get this error:

2023-01-11 17:59:00.776 [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-11 17:59:00.783 [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-11 17:59:00.789 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt | is_defined

2023-01-11 17:59:04.713 [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-11 17:59:04.720 [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-11 17:59:04.728 [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-11 17:59:04.735 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt | is_defined

As it is an OpenMQTTGateway thread I was thinking that you were using OMG.

For Theengs Gateway the key is HAAS_DISCOVERY: false but I think the issue is that you are using a previous docker version, please take it from below:
https://hub.docker.com/r/theengs/gateway

Still the same :frowning:

  theengsgateway:
    image: theengs/gateway
    container_name: theengsgateway
    network_mode: host
    environment:
      MQTT_HOST: xxx
      MQTT_USERNAME: xxx
      MQTT_PASSWORD: xxx
      MQTT_PUB_TOPIC: home/TheengsGateway/BTtoMQTT
      MQTT_SUB_TOPIC: home/TheengsGateway/commands
      PUBLISH_ALL: true
      TIME_BETWEEN: 60
      SCAN_TIME: 60
      LOG_LEVEL: DEBUG
      HAAS_DISCOVERY: false
      DISCOVERY: true
      DISCOVERY_TOPIC: homeassistant/sensor
      DISCOVERY_DEVICE_NAME: TheengsGateway
      DISCOVERY_FILTER: "[IBEACON,GAEN,MS-CDP]"
      SCANNING_MODE: active
      ADAPTER: hci0
    volumes:
      - /var/run/dbus:/var/run/dbus


2023-01-11 20:01:15.295 [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-11 20:01:15.303 [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-11 20:01:15.311 [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-11 20:01:15.318 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt | is_defined

I get every minute:


2023-01-11 20:52:13.654 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.hum

2023-01-11 20:52:13.658 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.volt

2023-01-11 20:52:13.662 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.batt

try to read Mi temperature and humidity 2 with OMG. I have 4 temp and humidity devices.
The Status in Openhab is unknown. It takes several hours for changing the status to online.

any ideas!? Im running Openhab 3.4.1