External Temp/Baro with METAR script

Moderator: leecollings

Post Reply
ld57
Posts: 11
Joined: Sunday 31 July 2016 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

External Temp/Baro with METAR script

Post by ld57 »

Hi!

I've just finished my 1st Domoticz script: it will give you external temperature and barometer by querying METAR (https://en.wikipedia.org/wiki/METAR) stations.

1- Make sure you have the "curl" package on your PI
2- Simply find your nearest METAR stations and edit the station variable below.
3- Idx is of course the index of a virtual sensor "Temp + Humidity + Baro".

script_time_metar.lua:

Code: Select all

-- METAR time script

local idx = 10
local station = "LFJL"

command = "curl http://tgftp.nws.noaa.gov/data/observations/metar/stations/" .. station .. ".TXT"
commandArray = {}

local m = os.date('%M')
if (m % 30 == 5) then
        -- update at 5 and 35 minutes of every hour
        local handle = io.popen(command)
        local data = handle:read("*a")
        handle:close()

        if (data == '') then
                 print("Error metar data not fetched")
                 return
        end
        
        data = string.gsub(data, "M", "-")
        local pres = tonumber(string.match(data, ' Q([0-9]+)'))
        local temp = tonumber(string.match(data, ' ([-0-9]+)/[-0-9]+ '))
        local dew = tonumber(string.match(data, ' [-0-9]+/([-0-9]+) '))
        local fore = 5

        -- very basic prediction
        if (pres < 1000) then
                fore = 4
        elseif (pres < 1020) then
                fore = 3
        elseif (pres < 1030) then
                fore = 2
        else    
                fore = 1
        end
        -- print (data, pres, temp)
        local hum = 100*(math.exp((17.625*dew)/(243.04+dew))/math.exp((17.625*temp)/(243.04+temp)))   
        
        
        commandArray[1] = {['UpdateDevice'] = idx .. '|0|' .. temp .. ';' .. hum .. ';0;' .. pres .. ';' .. fore}
end

return commandArray
It will run 2 times per hour since METAR data is not updated often.
I may improve that script with weather prediction soon.

Enjoy!
Last edited by ld57 on Tuesday 03 January 2017 20:05, edited 1 time in total.
Domoticz + RPI3B+ + Zwave devices + RFLink
My blog: https://drolez.com/blog/
ld57
Posts: 11
Joined: Sunday 31 July 2016 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: External Temp/Baro with METAR script

Post by ld57 »

Hi!
I've updated the script so that the 'metar' package is no longer needed, only curl. I also added basic weather prediction and humidity calculation.
Enjoy!
Domoticz + RPI3B+ + Zwave devices + RFLink
My blog: https://drolez.com/blog/
pavelbor
Posts: 35
Joined: Sunday 18 December 2016 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Tallinn / Estonia
Contact:

Re: External Temp/Baro with METAR script

Post by pavelbor »

Hello,

looks like script does not handle minus temperatures.
M04/M07 indicates the temperature is −4 °C (25 °F) and the dew point is −7 °C (19 °F). An M in front of the number indicates that the temperature/dew point is below zero Celsius.

Code: Select all

local temp = tonumber(string.match(data, ' ([0-9]+)/[0-9]+ '))
Spoiler: show
METAR:
2017/01/03 12:20
EETN 031220Z 23005KT 180V260 9999 3600E -SHSN BKN009 FEW014CB BKN032 M04/M07 Q0999 RESHSN R08/490395 NOSIG
ld57
Posts: 11
Joined: Sunday 31 July 2016 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: External Temp/Baro with METAR script

Post by ld57 »

Thanks! I've just updated the script above to fix this bug :)
Domoticz + RPI3B+ + Zwave devices + RFLink
My blog: https://drolez.com/blog/
pavelbor
Posts: 35
Joined: Sunday 18 December 2016 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version: LastBeta
Location: Tallinn / Estonia
Contact:

Re: External Temp/Baro with METAR script

Post by pavelbor »

Thanks for quick reply! Good job!

Would be nice to add wind information from METAR data into Domoticz WIND type dummy sensor.

12012MPS indicates the wind direction is from 120° (east-southeast) at a speed of 12 m/s (23 knots; 27 mph; 44 km/h). Speed measurements can be in knots (abbreviated KT) or meters per second (abbreviated MPS).
090V150 indicates the wind direction is varying from 90° true (east) to 150° true (south-southeast).
lost
Posts: 659
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: External Temp/Baro with METAR script

Post by lost »

pavelbor wrote:Thanks for quick reply! Good job!

Would be nice to add wind information from METAR data into Domoticz WIND type dummy sensor.

12012MPS indicates the wind direction is from 120° (east-southeast) at a speed of 12 m/s (23 knots; 27 mph; 44 km/h). Speed measurements can be in knots (abbreviated KT) or meters per second (abbreviated MPS).
090V150 indicates the wind direction is varying from 90° true (east) to 150° true (south-southeast).
Some airports already reports their data through open weather... and wind data is taken into account.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest