Domoticz - data download via JSON

Moderator: leecollings

Post Reply
prychol
Posts: 3
Joined: Friday 24 April 2020 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Polska
Contact:

Domoticz - data download via JSON

Post 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"}?
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Domoticz - data download via JSON

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
prychol
Posts: 3
Joined: Friday 24 April 2020 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Polska
Contact:

Re: Domoticz - data download via JSON

Post 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 
}
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests