Temp for Wunderground

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

Moderator: leecollings

Post Reply
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Temp for Wunderground

Post 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
}
Last edited by javalin on Saturday 06 March 2021 18:43, edited 1 time in total.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Temp for Wunderground

Post by EddyG »

I don't know the answer, but I think you should not expose your API key. Edit your post.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temp for Wunderground

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

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Temp for Wunderground

Post by javalin »

Ohhh, I forgot define httpReponses. Thank you!!
Last edited by javalin on Saturday 06 March 2021 16:53, edited 1 time in total.
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Temp for Wunderground

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

Who is online

Users browsing this forum: No registered users and 1 guest