Page 1 of 1

Domoticz - data download via JSON

Posted: Thursday 03 February 2022 18:21
by prychol
Hello. First I would like to apologize for my English, but I use Google translator :)
I have an air purity sensor from which I would like to have readings in Domoticz.
I read the data from the sensor after entering http: // SENSOR_IP_ADDRESS / data.json and receive the data in this format:

Code: Select all

{"software_version": "NAMF-2020-43", "age":"104", "measurements":"868", "uptime":"146292", "sensordatavalues":[{"value_type":"SDS_P1","value":"33.50"},{"value_type":"SDS_P2","value":"17.50"},{"value_type":"HECA_temperature","value":"5.39"},{"value_type":"HECA_humidity","value":"90.06"},{"value_type":"HECA_Tdc","value":"0.00"},{"value_type":"HECA_RHdc","value":"100.00"},{"value_type":"HECA_dc","value":"100.00"},{"value_type":"BME280_temperature","value":"3.44"},{"value_type":"BME280_pressure","value":"99522.66"},{"value_type":"BME280_humidity","value":"92.49"},{"value_type":"samples","value":"105264"},{"value_type":"min_micro","value":"1290"},{"value_type":"max_micro","value":"138996"},{"value_type":"signal","value":"-80"}]}
How to write a script to extract, for example, data to the "humi_AIR" switch with IDX: 123 from the {"value_type" section: "BME280_humidity", "value": "93.70"}?

Re: Domoticz - data download via JSON

Posted: Thursday 03 February 2022 20:22
by waltervl
You can use the http poller and parser for json see wiki https://www.domoticz.com/wiki/HTTP/HTTPS_poller
Example parsing scripts are in domoticz/scripts/lua_parsers

Re: Domoticz - data download via JSON

Posted: Thursday 03 February 2022 20:49
by prychol
I found an example like this and tried to rewrite it, but it doesn't work and I don't know what's wrong:

Code: Select all

return  { 
    on  =  { 
        timer  =  {  'every 1 minutes'  }, 
        httpResponses  =  {  'BME280_humidity'  } 
    }, 
    execute  =  function ( domoticz,  item ) 
        if  ( item.isTimer )  then 
            domoticz.openURL ({ 
            url  =  'http://192.168.0.68/data.json' , 
            method  =  'GET' , 
            callback  =  'BME280_humidity' 
            }) 
        elseif  (pozycja.isHTTPResponse )  to 
            if  ( item.ok )  then  - statusCode == 200
                local  humidity  =  item.json.BME280_humidity 
                domoticz.devices('Wilgotność_AIR').updateHumidity(humidity) 
            end 
        end 
    end 
}