Page 1 of 1

DzVents JSON with SHT3x-0x44 sensor

Posted: Saturday 15 February 2020 20:57
by cncforhobby
Hello,

I am new to this forum, so please let me know if this topic should be put somewhere else.
At this moment I use a Sonoff S20 with tasmota firmware and a BME280 sensor connected to it.
I have no problems at all with this code (will show the problem in a bit!)

I send a http request :

Code: Select all

http://192.168.10.4/cm?cmnd=status%2010 
which receives:

Code: Select all

{
"StatusSNS": {
"Time": "2020-02-15T20:37:04",
"BMP180": {
"Temperature": 17.3,
"Pressure": 1008.4
},
"PressureUnit": "hPa",
"TempUnit": "C"
}
}
Update the temperature and baro to a sensor in Domoticz:

Code: Select all

	
if (item.isHTTPResponse) then 

			if (item.statusCode == 200) then
				if (item.isJSON) then

					local myTemperature = item.json.StatusSNS.BMP180.Temperature
                                        local myPressure = item.json.StatusSNS.BMP180.Pressure
             					
             					-- update device in Domoticz
				domoticz.devices('Sonoff_TB').updateTempHumBaro(myTemperature,'0','0', myPressure)
				
The problem occurrs with my new SHT-31 sensor wich names itself SHT3X-0x44

The resonse:

Code: Select all

{
"StatusSNS": {
"Time": "2020-02-15T20:45:10",
"SHT3X-0x44": {
"Temperature": 19.6,
"Humidity": 54.1
},
"TempUnit": "C"
}
}
The code I use to get the value is the same:

Code: Select all

local myTemperature = item.json.StatusSNS.SHT3X-0X44.Temperature
But (off course) the code doesn't get the "-0x44". I tried to work around it but that doesn't solved the problem...

Code: Select all

local myTemperature = item.json.StatusSNS.'SHT3X-0X44'.Temperature
and
local myTemperature = item.json.StatusSNS."SHT3X-0X44".Temperature
Does anybody know a workaround for this?

Thanks in advance.

Re: DzVents JSON with SHT3x-0x44 sensor  [Solved]

Posted: Saturday 15 February 2020 21:27
by boum
Try:

Code: Select all

local myTemperature = item.json.StatusSNS['SHT3X-0X44'].Temperature
In Lua, the dot is used to access table element as a syntactic sugar, so this strictly is equivalent to:

Code: Select all

local myTemperature = item['json']['StatusSNS']['SHT3X-0X44']['Temperature']

Re: DzVents JSON with SHT3x-0x44 sensor

Posted: Saturday 15 February 2020 21:42
by cncforhobby
Hi! Thanks for the quick reply. It's working now!!! :D :D :D

I just had to use the line below with 0x44 instead of 0X44

Code: Select all

local myTemp = item['json']['StatusSNS']['SHT3X-0x44']['Temperature']