Not sure if you have a special case and this is in purpose, but right now you have two MQTT brokers configured, which will be rather challenging to configure.
Remember, the basic information flow is device <–> MQTT broker <–> OH2
In the best case you have now:
device1 <–> MQTT embedded <–> OH2
device2 <–> MQTT Mosquitto <-------^
While OH2 can likely handle two brokers, it will be challenging to remember who does what (unless you have a special case and this is on purpose). OH2 provides an embedded broker for convenience and hence, maybe you want to delete the Mosquitto broker you had set up (or vice versa if this is your preference).
A few more things to remember:
127.0.0.1 always points to the local machine (whichever that is); if you are unsure, just use the real IP address in all cases.
Clear the Cache can be your friend if you work on configs a lot and get weird results
in any case, do it step-wise: first check if you device connects to the broker, than check if OH2 connects to the broker; and if both, check then you get to content and items, etc. You can use a separate program to connect to your broker with your computer and see what is happening: MQTT Exploration App (as well as read incoming commands or post MQTT messages)
I’ve made the change to 2.5.0.M3, removed and reinstalled the embedded broker and binding. I did not install the auto-generated thing and am configuring it in a thing file. As of today my device (TH16 with SI7021 sensor) is at least partially working; I can control the switch (super happy about that!) but cannot pull the sensor data out. The current entries in the .things files are:
I can control the switch remotely any all is happy. When I begin to attempt to create a Channel to pull out the temperature, any configuration I try either does nothing or messes up the operation of the switch.
The Sonoff TH is sending out the following string from its sensor, seen from the Sonoff console:
I’ve tried the following channel configurations (separately of course) without luck (I have the JSON transformation installed):
Type number : Temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR:SI7021:Temperature"]
Type number : temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]
I’ve found some variations out there in the community pages but none work to pull the temperature number over.
I agree, I think it should! But it immediately breaks the switch and still doesn’t transmit the temperature! I’d actually be ok without the switch working and in fact tried leaving the temperature channel and removed the switch channel, and it still doesn’t transmit…
Could the JSON transform be malfunctioning somehow?
Thanks, Peter. Your input was the basis for most of my testing but still not functioning.
I did discover one potential conflict: Within my .thing file in defining my thing topic I used Sonoff_Coop but also used this in the Sonoff configuration file and in the .item. I changed the topic line to
…changing the thing name to include _Thing at the end. It now fixes the conflicts I had with the switch being disabled but am still not getting the temperature feed… :o(
Well that worked! I have a temperature coming through!
At least it worked for a few minutes, now my embedded broker is broken, for some unknown reason. Grrr. I don’t think this could get any more ridiculous. Commented out all of my changes, three restarts and still "OFFLINE - COMMUNICATION_ERROR
As the broker attempts to connect, I’m getting these entries in the logs:
2019-10-06 19:45:38.717 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid paho69680369956 and file store '/var/lib/openhab2/mqtt/127.0.0.1'
2019-10-06 19:45:39.554 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to '127.0.0.1'. Next attempt in 10000ms
I don’t somehow have a permissions issue on that folder that I never had before?
Don’t know if it helps or if you already changed it, but I saw that your clientID in the Bridge is written as clientid, but I think it should be clientID.
I updated the clientID tag but there was no change; not a surprise, it was working perfectly well before.
Recap on where I am:
Recently updated to 2.5.0.M3
The “MQTT Broker Moquette 2.5.0.M3” is installed
The “MQTT Binding 2.5.0.M3” is installed
I did not install the suggested MQTT thing; I have a bridge, thing and channels in a .things file as:
Bridge mqtt:broker:mqttbroker "MQTT Broker" [ host="127.0.0.1", secure=false, port=1883, qos=0, retain=false, clientID="openhab", keep_alive_time=30000, reconnect_time=60000 ]
{
Thing topic Sonoff_Coop_Thing "Sonoff Coop" @ "openhab" {
Channels:
Type switch : power "Power" [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]
Type number : temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]
Type number : humidity "Humidity" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity"]
}
}
My .items file contains:
Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature> { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:temperature"}
Number Sonoff_Coop_Humidity "Coop Humidity [%s %%]" <humidity> {channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:humidity"}
The broker was working right up to the time that the Temperature data started displaying from my Sonoff TH16 on my sitemap, then suddenly the broker just stopped working.
My openhab.log file is continuously displaying the following entries:
2019-10-08 20:20:18.172 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to '127.0.0.1'. Next attempt in 10000ms
2019-10-08 20:20:18.173 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid openhab and file store '/var/lib/openhab2/mqtt/127.0.0.1'
And the events.log repeats:
2019-10-08 20:21:48.192 [hingStatusInfoChangedEvent] - 'mqtt:broker:mqttbroker' changed from OFFLINE (COMMUNICATION_ERROR): Unable to connect to server to OFFLINE
2019-10-08 20:21:48.197 [hingStatusInfoChangedEvent] - 'mqtt:broker:mqttbroker' changed from OFFLINE to OFFLINE (COMMUNICATION_ERROR): Unable to connect to server
I’ve uninstalled the broker and binding and rebooted, no change.
In defining the thing, a file “127.0.0.1” is created that includes a lot of characters in addition to my .things file entries. Could this file be corrupt? What if I deleted the file and restarted?
No extra .things File with the above parameters. Of course I have the Bridge and Things in one file too. (it’s just the Thing-Part which I posted)
I don’t quite understand
Who and where a file “127.0.0.1” was created and what’s the content?
My .things-File looks similar to yours(Just a snippet of mine):
Bridge mqtt:broker:hans "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="OH2_hans" ]
{
// Sonoff Basic
Thing topic basic03 "Sonoff Basic 03 Schreibtischlampe" @ "MQTT2" {
Channels:
Type switch : power "Power " [ stateTopic="stat/basic_03/POWER", commandTopic="cmnd/basic_03/POWER" ]
Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/basic_03/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
Type string : version "Firmware Version " [ stateTopic="stat/basic_03/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
Type switch : reachable "Reachable" [ stateTopic="tele/basic_03/LWT",transformationPattern="MAP:reachable.map" ]
// Trigger String : powerx "Power x Trigger Test " [ stateTopic="stat/basic_03/POWER" ] // seems not to work with this syntax
// Type switch : powerx "Power X" [ stateTopic="stat/basic_03/POWER", trigger=true ] // Trigger Channel; no need to define an item // Test with Channel Event Trigger - test_mqtt.rules
}
Thing topic basic04 "Sonoff Basic 04 Kugellampe" @ "MQTT2" {
Channels:
Type switch : power "Power " [ stateTopic="stat/basic_04/POWER", commandTopic="cmnd/basic_04/POWER" ]
Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/basic_04/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
Type string : version "Firmware Version " [ stateTopic="stat/basic_04/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
Type switch : reachable "Reachable" [ stateTopic="tele/basic_04/LWT",transformationPattern="MAP:reachable.map" ]
}
// Sonoff Touch Wall Switches (T1, Touch)
Thing topic T101 "Sonoff T1 01 DeckenLampe York" @ "MQTT2" {
Channels:
Type switch : power "Power " [ stateTopic="stat/T1_01/POWER", commandTopic="cmnd/T1_01/POWER" ]
Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/T1_01/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
Type string : version "Firmware Version " [ stateTopic="stat/T1_01/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
Type switch : reachable "Reachable" [ stateTopic="tele/T1_01/LWT",transformationPattern="MAP:reachable.map" ]
}
.......
}
but I haven’t installed an embedded or a system broker, as I’m already use my former installed Mosquitto-Broker.
When starting/restarting openHAB the INFO
2019-10-08 08:29:16.452 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid OH2_hans and file store '/var/lib/openhab2/mqtt/localhost'
is normal, as you can see. I got it too. But the second information I’d never seen. Maybe it comes from the additional parameters in your Bridge-Configuration, which is a bit different to mine.