[SOLVED] Sonoff MQTT connection fail

Hello,

I’m trying to connect a Sonoff with Openhabian, but appears all the time “MQT: Connect failed to openhabianpi:1883, rc -2. Retry in 60 sec”

I already did the test of the Mosquitto Broker, by sending messages and I verified that it is received.
Yet, appears that the Mosquitto Broker is not accepting new devices.

I read some posts, I try several solutions, but continue to appear this error.

Anyone can help me?
Thank you.

Can you post your mqtt config, and items?

Sure, sorry :smiley:

The items are:
Switch Kitchen_Light “Luz” (Kitchen, gLight) {mqtt=">[broker:tasmota/cmnd/kitchenLightSonoff/POWER:command:*:default], <[broker:tasmota/stat/kitchenLightSonoff/POWER:state:default]"}

the rest of the items are equal to this one, at this moment I’m trying only with this one.

The MQTT.config is like this:
broker.url=tcp://localhost:1883
broker.clientId=openhabianpi
broker.user=openhabian
broker.pwd=openhabian

For testing, try commenting out your broker.clientId=openhabianpi in the MQTT config.

Also test with broker.url=tcp://OH IP:1883, where OH IP is your local IP ex. 10.0.1.15.

Then try removing tasmota in the items.file ( not knowing what your sonoff device config looks like, full topic or no) like this: {mqtt=">[broker:cmnd/kitchenLightSonoff/POWER:command:*:default], <[broker:stat/kitchenLightSonoff/POWER:state:default]"}

Here is a snapshot of sonoff setup

and here is what the item file looks like:

Switch LivingRoom_Light "Living Room Light" <light> ["Lighting"] 
	{ mqtt=">[pibroker:cmnd/sonoff11/POWER:command:*:default],
	<[pibroker:stat/sonoff11-3C0826/POWER:state:default]" }

I did all you said, continue to appear the connection fail, and at this moment in the log of the openhabian appear this error:
“2018-08-31 16:25:37.614 [ERROR] [org.apache.felix.configadmin ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=317, bundle=200/mvn:org.openhab.action/org.openhab.action.mqtt/1.12.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.12.0”

uninstall the MQTT action binding and use only the MQTT binding listed in Bindings

I unistall the MQTT action and persistence, only having the MQTT binding.
It starts to work.

I did some tests, I change the host in Sonoff to a name again. At that moment appear the error again, so I put the IP again.

Thank you for solving my problem. But this means that if the IP of the openhabian changes, I need to change the IP in all the Sonoff. Do you know what I can do?

It’s best to make your OH IP address static/fixed (usually done by adding the MAC address of your server) in the router so it doesn’t change. By default you should have mapdb as persistence just check the persistence file and add your items if needed.That should not have caused your issue. As you work with openhab keep a separate browser open with your logs and read them as you make changes. You will pick up on how to identify issues in no time. :wink:
If you start using sonoff GPIO 14 for sensors and what to chart the value you will need to use a different persistence.

I’m using openhabian and sonoff. I have changed the hostname via openhabian-config and can use this name on all sonoff devices for the MQTT broker hostname.
Can you connect to your raspi using the name or do you need thei IP for that as well?

As a conclusion of this topic, and with the tests I did, I’m not able to put a name in my host.
It only works when I put the IP in the Sonoff.
Two days ago I had everything working with a name in the Host.
At this moment it is working in this way, so it is good :slight_smile:

Thank you for your support, two days ago I had this working with 5 Sonoff and 2 of them with the AM2301.
Yesterday, it starts to do this error. So I’ll put everything together again.
I’ll follow your advice :slight_smile:

Same sensor, just using an ESP8266. :grinning:

That’s so cool, how can i do the same?

Here’s the items file:

Group Home_Sensor_Chart (Office, Charts)
Number Home_Sensor_Chart_Period "Period" (Office)
Number ESP_Easy_Temp "Esp8266 Temp [%.1f °F]" <temperature> (Home_Sensor_Chart)
	{ mqtt="<[pibroker:/Esp/DS/Temp:state:default]" }

Number ESP_Easy_Humid "Esp8266 Humid [%.1f %%]" <humidity> (Home_Sensor_Chart)
	{ mqtt="<[pibroker:/Esp/DS/Humid:state:default]" }	

rrd4j persistence file:

Strategies {
	// for rrd chart cron strategy every minute
	everyMinute : "0 * * * * ?"
	// get data reduced for older values to keep database small
	everyHour : "0 0 * * * ?"
	everyDay : "0 0 0 * * ?"

	default = everyChange
}

Items {
	// additionally persist Items
	Home_Sensor_Chart* : strategy = everyUpdate, everyMinute
	ESP_Easy_Temp : strategy = everyUpdate, everyMinute
	ESP_Easy_Humid : strategy = everyUpdate, everyMinute
}

and the sitemap file:

Frame {
		Switch item=Home_Sensor_Chart_Period mappings=[0="1h", 1="12h", 2="Day", 3="Week", 4="Month"]
		Chart  item=Home_Sensor_Chart period=h   refresh=60000 visibility=[Home_Sensor_Chart_Period==0] //, Home_Sensor_Chart_Period=="Uninitialized"]
		Chart  item=Home_Sensor_Chart period=12h  refresh=60000 visibility=[Home_Sensor_Chart_Period==1]
		Chart  item=Home_Sensor_Chart period=D  refresh=60000 visibility=[Home_Sensor_Chart_Period==2]
		Chart  item=Home_Sensor_Chart period=W refresh=60000 visibility=[Home_Sensor_Chart_Period==3]
		Chart  item=Home_Sensor_Chart period=M   refresh=60000 visibility=[Home_Sensor_Chart_Period==4]
	}

Enjoy

I’ll try it.

Thank you for everything

Hello H102,

Can you give me support again? Sorry to boring you again :stuck_out_tongue:

I’m tried to replicate what you show to me about the graph. But the values appear strange, I divided into 2 graphs to try to see what is occuring. As you can see in the image, the values are strange. It is receiving the correct values, but it is drawing strange values.
The first graph represents the Temperature and the second the Humidity, I divided because (as you can see) the temperature have values so low that do not appear.

The items file have this code:

Group   HomeSensorChart (Home, Charts)
Group   HomeSensorChart2 (Home, Charts)

Number HomeSensorChartPeriod "Periodo" (Home)
Number ValuesBathroomTemp       "Temperatura [%.2f ºC]" <temperature> (HomeSensorChart)
        {mqtt="<[broker:tele/kitchenLightSonoff/SENSOR:state:JSONPATH($.AM2301.Temperature)]"}
Number ValuesBathroomHumi       "Humidade [%.1f %%]" <humidity> (HomeSensorChart2)
        {mqtt="<[broker:tele/kitchenLightSonoff/SENSOR:state:JSONPATH($.AM2301.Humidity)]"}

The sitemap file have this code:

Text item=ValuesBathroomTemp label="Temperatura [%.1f ºC]" icon="temperature"
        Text item=ValuesBathroomHumi label="Humidade [%.1f %%]" icon="humidity"

        Switch item=HomeSensorChartPeriod mappings=[0="1h", 1="12h", 2="Day", 3="Week", 4="Month"]
        Chart  item=HomeSensorChart period=1h   refresh=60000 visibility=[HomeSensorChartPeriod==0]
        Chart  item=HomeSensorChart period=12h  refresh=60000 visibility=[HomeSensorChartPeriod==1]
        Chart  item=HomeSensorChart period=D  refresh=60000 visibility=[HomeSensorChartPeriod==2]
        Chart  item=HomeSensorChart period=W refresh=60000 visibility=[HomeSensorChartPeriod==3]
        Chart  item=HomeSensorChart period=M   refresh=60000 visibility=[HomeSensorChartPeriod==4]

        Chart  item=HomeSensorChart2 period=1h   refresh=60000 visibility=[HomeSensorChartPeriod==0]
        Chart  item=HomeSensorChart2 period=12h  refresh=60000 visibility=[HomeSensorChartPeriod==1]
        Chart  item=HomeSensorChart2 period=D  refresh=60000 visibility=[HomeSensorChartPeriod==2]
        Chart  item=HomeSensorChart2 period=W refresh=60000 visibility=[HomeSensorChartPeriod==3]
        Chart  item=HomeSensorChart2 period=M   refresh=60000 visibility=[HomeSensorChartPeriod==4]

And the persist file have this code:

Strategies {
        // for rrd chart cron strategy every minute
        everyMinute : "0 * * * * ?"
        // get data reduced for older values to keep database small
        everyHour : "0 0 * * * ?"
        everyDay : "0 0 0 * * ?"
        default = everyChange
}

Items {
        // additionally persist Items
        HomeSensorChart* : strategy = everyUpdate, everyMinute
        HomeSensorChart2* : strategy = everyUpdate, everyMinute
        ValuesBathroomTemp : strategy = everyUpdate, everyMinute
        ValuesBathroomHumi : strategy = everyUpdate, everyMinute
}

As you can see, it is almost equal to your code. But the values are strange.

Since you are persisting the items directly (and not only the groups) you could use the items directly on the charts (you are showing one item per chart anyway). I’d try that.
If that doesn’t help try stopping OH, deleting all .rrd files (to be found in /ar/lib/openhab2/persistence/rrd4j) and restarting OH.
Such is needed if (for example) the item type has been changed after the .rrd file has been created.

I’m using the same setup, however without the groups, and my charts are working as the ones from @H102. Your basic setup seems to correct (see the actual temp and humidity readings), the problem is either with the database or the chart creation.

Thanks @opus for pointing that out I should have caught that.

@JAF if needed, you can do this to clean up your system:

  1. Stop OH if it is running. ```
    sudo systemctl stop openhab2.service
2. Delete the contents of /var/lib/openhab2/cache and /var/lib/openhab2/tmp. For manual installations these folders are in your OH home folder under userdata. DO NOT DELETE THE FOLDERS THEMSELVES, JUST THE CONTENTS.
3. Start OH. ```
sudo systemctl start openhab2.service

Sorry, I do not understand what do you mean with this phare:

Can you explain me again?

Items {
        // additionally persist Items
        HomeSensorChart* : strategy = everyUpdate, everyMinute
        HomeSensorChart2* : strategy = everyUpdate, everyMinute
        ValuesBathroomTemp : strategy = everyUpdate, everyMinute
        ValuesBathroomHumi : strategy = everyUpdate, everyMinute
}

Your item ValuesBathroomTemp is not needed because it’s already being persisted by the items group HomeSensorChart*.

My chart is working with both items listed as shown above (item and group in persistence), but it shouldn’t be required to list both. You can test by commenting out the item and use only the Group with // . Like this:

Items {
        // additionally persist Items
        HomeSensorChart* : strategy = everyUpdate, everyMinute
        HomeSensorChart2* : strategy = everyUpdate, everyMinute
//      ValuesBathroomTemp : strategy = everyUpdate, everyMinute
//      ValuesBathroomHumi : strategy = everyUpdate, everyMinute
}

If your still having an issue, test further by commenting out HomeSensorChart2* and try to get just one reading to chart, then add on.