{"id":1937,"date":"2018-02-14T22:56:53","date_gmt":"2018-02-14T20:56:53","guid":{"rendered":"https:\/\/einstein.amsterdam\/?page_id=1937"},"modified":"2018-02-14T22:56:53","modified_gmt":"2018-02-14T20:56:53","slug":"domoticz-metar-script","status":"publish","type":"page","link":"https:\/\/einstein.amsterdam\/?page_id=1937","title":{"rendered":"Domoticz METAR Script"},"content":{"rendered":"<p>Metar script<br \/>\nLua time script<\/p>\n<blockquote><p>&#8212; METAR time script<\/p>\n<p>local idx = 103<br \/>\nlocal station = &#8220;EHAM&#8221;<\/p>\n<p>command = &#8220;curl http:\/\/tgftp.nws.noaa.gov\/data\/observations\/metar\/stations\/&#8221; .. station .. &#8220;.TXT&#8221;<br \/>\ncommandArray = {}<\/p>\n<p>local m = os.date(&#8216;%M&#8217;)<br \/>\nif (m % 30 == 5) then<br \/>\n        &#8212; update at 5 and 35 minutes of every hour<br \/>\n        local handle = io.popen(command)<br \/>\n        local data = handle:read(&#8220;*a&#8221;)<br \/>\n        handle:close()<\/p>\n<p>        if (data == &#8221;) then<br \/>\n                 print(&#8220;Error metar data not fetched&#8221;)<br \/>\n                 return<br \/>\n        end<\/p>\n<p>        data = string.gsub(data, &#8220;M&#8221;, &#8220;-&#8220;)<br \/>\n        local pres = tonumber(string.match(data, &#8216; Q([0-9]+)&#8217;))<br \/>\n        local temp = tonumber(string.match(data, &#8216; ([-0-9]+)\/[-0-9]+ &#8216;))<br \/>\n        local dew = tonumber(string.match(data, &#8216; [-0-9]+\/([-0-9]+) &#8216;))<br \/>\n        local fore = 5<\/p>\n<p>        &#8212; very basic prediction<br \/>\n        if (pres < 1000) then\n                fore = 4\n        elseif (pres < 1020) then\n                fore = 3\n        elseif (pres < 1030) then\n                fore = 2\n        else    \n                fore = 1\n        end\n        -- print (data, pres, temp)\n        local hum = 100*(math.exp((17.625*dew)\/(243.04+dew))\/math.exp((17.625*temp)\/(243.04+temp)))   \n        \n        \n        commandArray[1] = {['UpdateDevice'] = idx .. '|0|' .. temp .. ';' .. hum .. ';0;' .. pres .. ';' .. fore}\nend\n\nreturn commandArray<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Metar script Lua time script &#8212; METAR time script local idx = 103 local station = &#8220;EHAM&#8221; command = &#8220;curl http:\/\/tgftp.nws.noaa.gov\/data\/observations\/metar\/stations\/&#8221; .. station .. &#8220;.TXT&#8221; <a class=\"mh-excerpt-more\" href=\"https:\/\/einstein.amsterdam\/?page_id=1937\" title=\"Domoticz METAR Script\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/pages\/1937"}],"collection":[{"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1937"}],"version-history":[{"count":1,"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/pages\/1937\/revisions"}],"predecessor-version":[{"id":1938,"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=\/wp\/v2\/pages\/1937\/revisions\/1938"}],"wp:attachment":[{"href":"https:\/\/einstein.amsterdam\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}