Page 1 of 1

Temp for Wunderground

Posted: Saturday 06 March 2021 11:44
by javalin
Hello, I am trying to get temperature value for a supposed json result without any success.I have not succeeded in any way so, either something I am doing wrong, or the result I get from the link is not json. I appreciate any help.

Code: Select all

local scriptVar = 'WundeMap'
return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },  

    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
		marker = 'WundeMap',
    },

    execute = function(dz, item)
    -- Send status to domoticz
        if item.isTimer then
            dz.openURL({
                url = 'https://api.weather.com/v2/pws/observations/current?apiKey=obfuscated&stationId=IMasxa4&numericPrecision=decimal&format=json&units=e',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return
        end
        if item.isHTTPResponse then
			if item.statusCode == 200 then
                if item.isJSON then 
                    rt = item.json
                    local temp = rt.observations.imperial["temp"]  
                    dz.log(temp,dz.LOG_DEBUG)
                end
            end
        end
end
}

Re: Temp for Wunderground

Posted: Saturday 06 March 2021 11:55
by EddyG
I don't know the answer, but I think you should not expose your API key. Edit your post.

Re: Temp for Wunderground

Posted: Saturday 06 March 2021 12:18
by waaren
javalin wrote: Saturday 06 March 2021 11:44 I am trying to get temperature value for a supposed json result without any success.I have not succeeded in any way so, either something I am doing wrong, or the result I get from the link is not json. I appreciate any help.
You forgot an essential part in the on section and the table lay-out is a bit different.

Code: Select all

local scriptVar = 'WundeMap'
return
{
    on =
    {
        timer =
        {
            'every 1 minutes',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'WundeMap',
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url = 'https://api.weather.com/v2/pws/observations/current?apiKey=obfuscated&stationId=IMONCA14&numericPrecision=decimal&format=json&units=e',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return

        elseif item.json then
            local rt = item.json.observations[1]
            local temp = rt.imperial.temp
            dz.log(temp,dz.LOG_DEBUG)

        else
            dz.log('Problem with return ', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end
    end
}


Re: Temp for Wunderground

Posted: Saturday 06 March 2021 14:07
by javalin
Ohhh, I forgot define httpReponses. Thank you!!

Re: Temp for Wunderground

Posted: Saturday 06 March 2021 14:54
by javalin
EddyG wrote: Saturday 06 March 2021 11:55 I don't know the answer, but I think you should not expose your API key. Edit your post.
Thank you but is not my station data.