[SOLVED] Openhab and Sonoff TH16

Hi to all
I have a sonoff TH16 with sensor AM2301.
I have this mqtt.cfg:

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
 localbroker.url=tcp:localhost:xxx
 # Optional. User id to authenticate with the broker.
 localbroker.user=xxxxx
 # Optional. Password to authenticate with the broker.
 localbroker.pwd=xxxxx

my items are:

 Switch sonoffTermostato "Interruttore Termostato"  <light> (LR,gLight)
 {channel="mqtt:topic:0cc91bf0:Power" }

  
Number sonoffTermostato_Humidity "Humidity [%.1f]"  
{ mqtt="<[localbroker:tele/sonoffTermostato/SENSOR:state:JSONPATH($.AM2301.Humidity)]" }

Number sonoffTermostato_Temp "Temperature" (sonoffTermostato, gTemperature) 
{ mqtt="<[localbroker:tele/sonoffTermostato/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }

my sitemaps is

 Frame label="LUCE FARO TERMOSIFONE" {
	   Default item=SonoffFaroSalotto
       Default item=sonoffTermostato
	   Default item=sonoffTermostato_Temp label="Temperatura [%.1f °C]" icon="temperature"
	   Default item=sonoffTermostato_Humidity label="Umidita' [%.1f %%]" icon="humidity"
                                    }



This is the information from the console of the sonoff:
14:30:26 MQT: tele/sonoffTermostato/STATE = {“Time”:“2019-06-01T14:30:26”,“Uptime”:“0T00:00:14”,“Vcc”:3.230,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“POWER”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“TP-LINK_88A51C”,“BSSId”:“64:66:B3:88:A5:1C”,“Channel”:3,“RSSI”:100,“LinkCount”:1,“Downtime”:“0T00:00:04”}}
14:30:26 MQT: tele/sonoffTermostato/SENSOR = {“Time”:“2019-06-01T14:30:26”,“AM2301”:{“Temperature”:23.9,“Humidity”:57.8},“TempUnit”:“C”}
14:30:36 MQT: stat/sonoffTermostato/RESULT = {“POWER”:“ON”}
14:30:36 MQT: stat/sonoffTermostato/POWER = ON
14:30:37 MQT: stat/sonoffTermostato/RESULT = {“POWER”:“OFF”}
14:30:37 MQT: stat/sonoffTermostato/POWER = OFF
14:30:38 MQT: stat/sonoffTermostato/RESULT = {“POWER”:“ON”}
14:30:38 MQT: stat/sonoffTermostato/POWER = ON
14:30:39 MQT: stat/sonoffTermostato/RESULT = {“POWER”:“OFF”}
14:30:39 MQT: stat/sonoffTermostato/POWER = OFF

my problem is that i not be able to see the value of the humidity and temperature.
Can you help me pls?

Your switch item is setup with the version 2 syntax, if switching is working you are using the version 2 of the mqtt binding.
In this case the items for temperature and humidity are setup wrong! Use the version 2 syntax as well.

Yes i use the MQTT Binding version 2.4.0
But what is the correct syntax?

How did you setup the thing channel for the power? Via file or via PaperUI? Did you create a generic MQTT thing or did you use automatic discovery?

ah ok i change

i am able to create the channel for the switch but i am not able to create a channel for the sensor.
Can you follow me pls?

it doesn’t work


my sitemaps:

 Frame label="LUCE FARO TERMOSIFONE" {
	   Default item=SonoffFaroSalotto
       Default item=sonoffTermostato
	  // Text item=sonoffTermostato_Temp label="Temperatura [%.1f °C]" icon="temperature"
	   Text item=sonoffTermostato_Humidity label="Umidita' [%.1f %%]" icon="humidity"
                                    }


my items

Number sonoffTermostato_Humidity "Humidity [%.1f]" <humidity> 
{channel="mqtt:topic:0cc91bf0:Sensor" }


You are missing the stateTopic!
In your case probably:
tele/sonoffTermostato/SENSOR

I modify the thing so:


in logviewer i have

2019-06-02 16:01:45.162 [WARN ] [l.generic.ChannelStateTransformation] - Transformation service TELE/SONOFFTERMOSTATO/SENSOR for pattern state:JSONPATH:$.AM2301.Humidity not found!

But it doesn’t work

i tried also this solution but nothing:

Do NOT change the working channel for the ON/OFF switch!
You need to create a separate Number channel for temperature and humidity!
For the incoming value transformation use:
JSONPATH:$.AM2301.Temperature and for the state topic the one I posted above.

You may have it working by now, if not here is an example of my mqtt thing and item for a working temp/humidity sensor.

Thing:

Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

Item:

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

You will need to change SI7021 to be whatever your sensor is. Hope this helps.

It doesn’t work
i created the three channels

i configured the channels so:


i created the link so:

the items are

Number sonoffTermostato_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:af184b0c:Temperatura" }
Number sonoffTermostato_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:af184b0c:Umidita" }
  

and the sitemamaps is

 Frame label="LUCE FARO TERMOSIFONE" {
	   Default item=SonoffFaroSalotto
       Default item=sonoffTermostato
	   Default item=sonoffTermostato_Humidity
	   Default item=sonoffTermostato_Temp
	  
	  
                                    }


and the result is:

where do i set the bridge?

I tried to do so but i need to define the Bridge also

To my understanding you had the power switch working!
If that is not the case, why don’t you restart with reading the Documentation.

i followed your istructions.

Did you created a MQTT Broker Thing that is connected to your broker? Without that no MQTT Thing and Item will work!
Did you connect your Generic MQTT Thing to that Broker Thing?
The stateTopic for the temperature and humidity must start with “tele” instead of “stat”!

ok it works.
One Thing:
why am i able to see the symbol “°C” on the Temperature?

You are missing only the Symbol for degree (°).
IMHO your sitemap has it correctly set. Honestly, I don’t know! (Language Setting?)

@fzonno
How did you save your .items File ? It has to be a UTF-8 Type.

1 Like