DzVents JSON with SHT3x-0x44 sensor  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
cncforhobby
Posts: 3
Joined: Sunday 12 January 2020 15:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: Waddinxveen, Netherlands
Contact:

DzVents JSON with SHT3x-0x44 sensor

Post 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.
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

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

Post 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']
cncforhobby
Posts: 3
Joined: Sunday 12 January 2020 15:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Location: Waddinxveen, Netherlands
Contact:

Re: DzVents JSON with SHT3x-0x44 sensor

Post 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']
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest