get value from json table containing spaces  [Solved]

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

Moderator: leecollings

Post Reply
DomoFlits
Posts: 48
Joined: Thursday 06 October 2016 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Bld16583
Location: The Netherlands
Contact:

get value from json table containing spaces

Post by DomoFlits »

I can get status values from my fan by calling http://192.168.1.220/api.html?get=ithostatus

This returns:

Code: Select all

{"temp":26.5,"hum":49.3,"ppmw":10853,"Speed status":44,"Internal fault":0,"Frost cycle":0,"Filter dirty":0,"AirQuality (%)":"not available","AirQbased on":0,"CO2level (ppm)":"not available","Indoorhumidity (%)":49,"Outdoorhumidity (%)":"not available","Exhausttemp (°C)":"not available","SupplyTemp (°C)":"not available","IndoorTemp (°C)":"not available","OutdoorTemp (°C)":"not available","SpeedCap":63488,"BypassPos (%)":"not available","FanInfo":"auto","ExhFanSpeed (%)":44,"InFanSpeed (%)":0,"RemainingTime (min)":0,"PostHeat (%)":"not available","PreHeat (%)":"not available","InFlow (l sec)":"not available","ExhFlow (l sec)":"not available","Ventilation setpoint (%)":44,"Fan setpoint (rpm)":1113,"Fan speed (rpm)":1116,"Error":0,"Selection":7,"Startup counter":16,"Total operation (hours)":184,"Absence (min)":0,"Highest CO2 concentration (ppm)":"not available","Highest RH concentration (%)":49,"RelativeHumidity":49.29,"Temperature":26.52}
I want to use fields 1 (temp), 2 (hum) and 4 (Speed status) in domoticz. (in below script I write them only to the log first, so I can see what is happening)
The temperature and humidity is not a problem, but the speed status is, since I don't know how to deal with spaces.

domoticz.log(item.json.Speed status) doesn't work
replacing "speed status" by "speed" using a local variable doesn't work also

does anyone has the :idea: for me how to use it?

I wrote this script:

Code: Select all

return {
    on = {
        timer = {
        'every 2 minutes',
        },
        httpResponses = { 'trigger' }
    },
	logging = {
--		level = domoticz.LOG_STATUS,
		level = domoticz.LOG_DEBUG,
		marker = 'itho-status',
	},
    execute = function(domoticz, item)
    if (item.isTimer) then
        domoticz.openURL({
            url = 'http://192.168.1.220/api.html?get=ithostatus',
            callback = 'trigger'
        })
    end
    if (item.isHTTPResponse) then
        if (item.ok) then
            if (item.isJSON) then
		local speed = "Speed status"
            	domoticz.log(item.json.temp)    
            	domoticz.log(item.json.hum)    
            	domoticz.log(item.json.speed)
            end
        end
    end
    end
}
Last edited by DomoFlits on Sunday 31 May 2026 19:02, edited 1 time in total.
User avatar
jvdz
Posts: 2485
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: get value from json table containing spaces  [Solved]

Post by jvdz »

Try:

Code: Select all

item.json["Speed status"]
DomoFlits
Posts: 48
Joined: Thursday 06 October 2016 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Bld16583
Location: The Netherlands
Contact:

Re: get value from json table containing spaces

Post by DomoFlits »

Thanks. this works.
I tried

Code: Select all

item.json.["Speed status"]
before but that didn't work :oops: . It had one dot ( . ) too many.

full working script for the next reader, including writing the values into (virtual) sensors in Domoticz:

Code: Select all

return {
    on = {
        timer = {
        'every 2 minutes',
        },
        httpResponses = { 'trigger' }
    },
	logging = {
		-- Level can be domoticz.LOG_INFO, domoticz.LOG_STATUS, domoticz.LOG_ERROR or domoticz.LOG_DEBUG
		level = domoticz.LOG_ERROR,
--		level = domoticz.LOG_DEBUG,
		marker = 'itho-status',
	},
    execute = function(domoticz, item)
    if (item.isTimer) then
        domoticz.openURL({
            url = 'http://192.168.1.220/api.html?get=ithostatus',
            callback = 'trigger'
        })
    end
    if (item.isHTTPResponse) then
        if (item.ok) then
            if (item.isJSON) then
--              domoticz.log(item.json.temp)            -- write value to log for debugging
--              domoticz.log(item.json.hum)             -- write value to log for debugging
--              domoticz.log(item.json["Speed status"]) -- write value to log for debugging
                domoticz.devices(342).updateTemperature(item.json.temp)             -- write value to Domoticz-sensor
                domoticz.devices(343).update(item.json.hum)                         -- write value to Domoticz-sensor
                domoticz.devices(341).updatePercentage(item.json["Speed status"])   -- write value to Domoticz-sensor
            end
        end
    end
end
}
Post Reply