OpenHAB first config with mqtt

Background:
I have an esp8266 flashed with tasmota and setup mqtt. I have a mosquitto broker setup with a simple .conf that seems to work. I get connection and subscrition data on MQTTExplorer and have connected other clients to the sensor as well.

Goal:
I would like to setup a openHAB with dashboard connect and visualize the data.
I have setup openhab-3.2.0 with zulu11.54.23-ca-jdk11.0.14-win_x64.
I have followed sever guides i have found, but none quick specific to my configuration and I am not sure I understand the configuration setup, and I’m afraid I make a beginner mistake somewhere but just can figure it out.
procedure:
add thing, generic mqtt thing, set bridge to mosquitto - STATUS ONLINE
add channel with connection to topic, e.g. from tasmota, or copied from MQTT explorer
– not sure this is right, so: tele/mydevice/sensor/temperature, but I only see “NULL” and I presume that should be the last published value.
What am I missing?

Can’t say which guides you followed, however:
Did you really create only one MQTT related thing?
You need:
a MQTT broker thing ( acts as a bridge between openHAB and MQTT, does need NO channel)
MQTT ( generic) things, connection to the above broker thing and having channels for all needed commands and states.

If you’d post the YAML code of your MQTT things we could give a better advice.

OK, well after days of search toptics and basic tutorials…
immediatly after posting this I found this:[OH3] Tasmota via MQTT Autodiscovery

which told me to setup auto discovery on the tasmota (I though auto discovery when the other way;)
it showed up in openHAB and my sensor readings work.
I had some configurations mixed up. Ill try to sort it out and post my errors;)

For info, it’s unlikely that the above is the actual topic if you’re using a normal Tasmota distribution. The topic is probably

tele/mydevice/sensor

which will receive a JSON payload. You would then use the state transformation field in your Time Channel to extract the temperature data using the JSONPATH Transformation Service. If you show the JSON payload we can help with the JSONPATH extraction.

But if you’ve got autodiscovery working, and you’re happy with it, then leave it!!

@opus
sorry I was not as specific as perhaps I should have been.
yes I setup the mqtt broker thing first; its online
then the generic thing, also online, but channels dont connect to anything (see latest update)

well, for educational purposes I would like to figure out how to set it up manually through paperUI.
I understand the topics are wrong (kinda expected) and the transformation is needed, but not sure yet how to go about doing that…

There’s not a lot of information in this thread to be able to categorically help you, but maybe this write up is useful? You could probably skip to step 6, but exact specifics will depend on the JSON payload from Tasmota.

1 Like

do i need the transformation? the autodiscovery thing, item works: shows temp and analyse chart, but i get and ERROR:COMM under channel links. this does not seem to use a transformation that i can tell.
The code section shows several topics listed, which I do not get when i go through the UI generic setup??? Do I have to write code or is it possible to get same setup through UI GUI?

Depending on the autodiscovery that you have enabled, you need to have the JINJA and JSONPATH transformations installed.

Show us.

Read through the link I posted above. It’s all possible through the UI.

What, you dont believe me…:wink:

There should be more info concerning this error in the logs!

I’m seeing this:

2022-02-06 22:36:30.786 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '{"Time":"2022-02-06T22:36:32","DHT11":{"Temperature":17.0,"Humidity":62.0,"DewPoint":9.7},"TempUnit":"C"}' not supported by type 'NumberValue'
java.lang.ClassCastException: class org.openhab.binding.mqtt.handler.BrokerHandler cannot be cast to class org.openhab.binding.mqtt.handler.AbstractBrokerHandler (org.openhab.binding.mqtt.handler.BrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @57bb9afe; org.openhab.binding.mqtt.handler.AbstractBrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @b944cb0)
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.getBridgeHandler(AbstractMQTTThingHandler.java:210) ~[?:?]
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.bridgeStatusChanged(AbstractMQTTThingHandler.java:173) ~[?:?]
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.initialize(AbstractMQTTThingHandler.java:227) ~[?:?]
	at org.openhab.binding.mqtt.generic.internal.handler.GenericMQTTThingHandler.initialize(GenericMQTTThingHandler.java:180) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-02-06 22:41:09.031 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'mqtt:topic:b1039df2e5:c89800bb8f': class org.openhab.binding.mqtt.handler.BrokerHandler cannot be cast to class org.openhab.binding.mqtt.handler.AbstractBrokerHandler (org.openhab.binding.mqtt.handler.BrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @57bb9afe; org.openhab.binding.mqtt.handler.AbstractBrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @b944cb0)
java.lang.ClassCastException: class org.openhab.binding.mqtt.handler.BrokerHandler cannot be cast to class org.openhab.binding.mqtt.handler.AbstractBrokerHandler (org.openhab.binding.mqtt.handler.BrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @57bb9afe; org.openhab.binding.mqtt.handler.AbstractBrokerHandler is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @b944cb0)
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.getBridgeHandler(AbstractMQTTThingHandler.java:210) ~[?:?]
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.bridgeStatusChanged(AbstractMQTTThingHandler.java:173) ~[?:?]
	at org.openhab.binding.mqtt.generic.AbstractMQTTThingHandler.initialize(AbstractMQTTThingHandler.java:227) ~[?:?]
	at org.openhab.binding.mqtt.generic.internal.handler.GenericMQTTThingHandler.initialize(GenericMQTTThingHandler.java:180) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]

The thing code (generic) looks like this:

UID: mqtt:topic:0123456789
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:987654321
channels:
  - id: Temp
    channelTypeUID: mqtt:number
    label: Temp
    description: ""
    configuration:
      transformationPattern: JSONPATH:$.AM2301.Temperature
      stateTopic: sensor/DC8855_DHT11_Temperature

Which is quit different then the autodiscovery code

There is something wrong or at least weird!
What type of sensor do you have installed? DH11 or AM2301?
The state-topic looks weird, as @hafniumzinc already said I would expect

tele/YourDeviceID/SENSOR

I have to admit: I am not used to Autodiscovery!

The code I have shown is from the generic manual setup. the static-topic i did however copy from the autodiscovery code as it is also weird, or unexpected, as I tryed to set a new name and topic (easier to remember/type), but somehow the default with MACID is getting crammed in there?

oh, and sorry I forgot to mention its a DHT11 sensor.

p.p.s everything is showing online now, no ERROR:COMM after a ESP reset. I was getting updated data before and after the reset though?? (on the autodiscovery thing only)

In this case the ( installed?) JSON-Transformation is wrong as it is searching for an AM2301 sensor.

Can’t make out any “MACID”, so no comment on that.

I believe according to tasmota docs the DC8855 is extracted from the MAC ID, or am I wrong. I did not choose that:)

You are talking about that string!
You could change that ( on tasmota-device webpage MQTT Config-topic).
Assuming your topic to be DC885 I would expect the stateTopiic setting to be

tele/DC8855/SENSOR

this assumption would be wrong. I have changed the mqtt config in Tasmota to more friendly ones. the said string appears above the topic dropbox (as default I presume)

EDIT:
In summary:
autodiscovery works fine :+1:
generic manual setup does NOT work: online, but NULL

MQTT broker: mosquitto → unchanged
tasmota → Mqtt config: chaned client to DHTclient; changed topic to DHT11
openHAB → add “generic Mqtt”; change Bridge to mosquitto;save
openHAB -? add channel, change to number value; add trasformation " JSONPATH:$.DHT11.Temperature"; change state topic “sensor/DC8855_DHT11_Temperature”; change id and label to DHT11
openHAB → add link; create new; DONE

Can you summarise what you have working, and what doesn’t work? And for the ones that don’t work, if you want help, can you share all these configurations that you changed? And the JSON payload sent by Tasmota?