luftdaten "nested" json  [Solved]

Easy to use, 100% Lua-based event scripting framework.
Post Reply
svde
Posts: 19
Joined: Sunday 17 April 2016 10:36
Target OS: Linux
Domoticz version:
Contact:

luftdaten "nested" json

Post by svde » Thursday 10 May 2018 9:57

I'm following https://www.domoticz.com/wiki/DzVents:_ ... ling_2.4.0 and trying to get data out of my luftdaten.info sensor. It gives back the http response and I can get data out of the top json values (like software_version and age), but how do I get to the nested ones (like the value of SDS_P1?

JSON response is:

Code: Select all

{
  "software_version": "NRZ-2017-099",
  "age": "104",
  "sensordatavalues": [
    {
      "value_type": "SDS_P1",
      "value": "13.37"
    },
    {
      "value_type": "SDS_P2",
      "value": "11.23"
    },
    {
      "value_type": "temperature",
      "value": "19.10"
    },
    {
      "value_type": "humidity",
      "value": "54.00"
    },
    {
      "value_type": "BME280_temperature",
      "value": "23.80"
    },
    {
      "value_type": "BME280_humidity",
      "value": "38.49"
    },
    {
      "value_type": "BME280_pressure",
      "value": "100476.89"
    },
    {
      "value_type": "samples",
      "value": "589419"
    },
    {
      "value_type": "min_micro",
      "value": "243"
    },
    {
      "value_type": "max_micro",
      "value": "26699"
    },
    {
      "value_type": "signal",
      "value": "-60"
    }
  ]
}
For the moment I'm logging these:

Code: Select all

domoticz.log(item.json.software_version)
domoticz.log(item.json.age)
domoticz.log(item.json.sensordatavalues)
which shows up as:

Code: Select all

2018-05-10 09:55:01.483  dzVents: Info:  ------ Start external script: luftdaten.lua: HTTPResponse: "luftdatenRetrieved"
2018-05-10 09:55:01.487  dzVents: Info:  NRZ-2017-099
2018-05-10 09:55:01.487  dzVents: Info:  125
2018-05-10 09:55:01.487  dzVents: Info:  {{["value"]="8.33", ["value_type"]="SDS_P1"}, {["value"]="5.37", ["value_type"]="SDS_P2"}, {["value"]="15.30", ["value_type"]="temperature"}, {["value"]="73.90", ["value_type"]="humidity"}, {["value"]="20.10", ["value_type"]="BME280_temperature"}, {["value"]="49.14", ["value_type"]="BME280_humidity"}, {["value"]="100752.16", ["value_type"]="BME280_pressure"}, {["value"]="590282", ["value_type"]="samples"}, {["value"]="238", ["value_type"]="min_micro"}, {["value"]="1129681", ["value_type"]="max_micro"}, {["value"]="-65", ["value_type"]="signal"}}
2018-05-10 09:55:01.488  dzVents: Info:  ------ Finished luftdaten.lua

dannybloe
Posts: 1433
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: luftdaten "nested" json  [Solved]

Post by dannybloe » Thursday 10 May 2018 10:03

It is an indexed table so you can do it like this:
item.json.sensorvalues[1].value
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests