Is already in the script but this sample uses the object names instead of GA’s.
Change in all lines grp.update('Weather precipitation', ... to grp.update('1/1/1', ... etcetera
BR,
Erwin
require('socket.http')
forecast = {}
function parsetag(parser, tag, attributes)
if tag == '27/3/0' then
table.insert(forecast, {})
elseif tag == '27/3/1' then
forecast[ #forecast ].symbol = attributes.name
elseif tag == '27/3/2' then
forecast[ #forecast ].precipitation = attributes.value
elseif tag == '27/3/3' then
forecast[ #forecast ].wind_direction = attributes.code
elseif tag == '27/3/4' then
forecast[ #forecast ].wind_speed = attributes.mps
elseif tag == '27/3/6' then
forecast[ #forecast ].temperature = attributes.value
elseif tag == '27/3/5' then
forecast[ #forecast ].pressure = attributes.value
end
end
[attachment=1217 Wrote:Erwin van der Zwart pid='11967' dateline='1550991145']
Hi,
I never said to change the TAG’s (:
if tag == 'youchangedthistogrpaddressesandthatiswrong'
BR,
Erwin
Of course you didnt. I may have to blame some saturday night fever or something. Changed it back to how it was supposed to be and then it is working..
But if i use any city in the world script is working. But using any Norwegian city i get that the service is stopped. And script not working. Kinda strange since it is an norwegian site.
26.02.2019, 10:25 (This post was last modified: 26.02.2019, 10:26 by FatMax.)
I made (partially found) a quick and dirty integration with met.no for a weather service a while back. Met.no is the same instance as YR.no.
Maybe someone can use (and improve, its messy) it. This version only collects the temperature and sends it to 1/1/0. Temperature is correct for the locations I have tried it. Loads of other information available in the output file. Also, you need to specify the correct longitude and latitude on the LM/SL for it to work.
Hello. I use weather script for https://www.yr.no/ . And next required for visualization- how much and what values can take variable forecast[1].symbol ( cloudy, rain...) to assign icons for each state?
Just log the table ‘current’ to see what index fields are available and if the data exists use it like the rest, could be something like current.moon_phase but you will know when looking at the data table.
Just log the table ‘current’ to see what index fields are available and if the data exists use it like the rest, could be something like current.moon_phase but you will know when looking at the data table.
BR,
Erwin
Hi Erwin,
Thanks for the reply, when i log astro i get this reply:
Apixu free tier does not provide astronomy data. Moon phase calculation is relatively simple. Here's a formula that gives number of days since new moon cycle:
Code:
1234567891011121314151617181920
localdate = os.date('*t')
localy, m, d = date.year, date.month, date.dayifm < 3theny = y - 1m = m + 12endlocala = math.floor(y / 100)
localb = math.floor(a / 4)
localc = 2 - a + blocale = math.floor(365.25 * (y + 4716))
localf = math.floor(30.6001 * (m + 1))
localjd = c + d + e + f - 1524.5localdn = jd - 2451549.5localnm = dn / 29.53localdc = (nm % 1) * 29.53log(dc)
(25.03.2019, 07:34)admin Wrote: Apixu free tier does not provide astronomy data. Moon phase calculation is relatively simple. Here's a formula that gives number of days since new moon cycle:
Code:
1234567891011121314151617181920
localdate = os.date('*t')
localy, m, d = date.year, date.month, date.dayifm < 3theny = y - 1m = m + 12endlocala = math.floor(y / 100)
localb = math.floor(a / 4)
localc = 2 - a + blocale = math.floor(365.25 * (y + 4716))
localf = math.floor(30.6001 * (m + 1))
localjd = c + d + e + f - 1524.5localdn = jd - 2451549.5localnm = dn / 29.53localdc = (nm % 1) * 29.53log(dc)
Thanks Admin,
Is there a way to get what phase the moon is in right now?
require('socket.http')
---------------------------------------------------------------------------------------------------------------------------------- Weather forecast from Yr, delivered by the Norwegian Meteorological Institute and the NRK-- -- This is a combo of the codes contributions from the Admin, Thomas, and me MichelDeLigne---- Usage:-- * Define your place in the variable url in the function yrno_fetch()---- * Ending the url with "forecast_hour_by_hour.xml" will give access to the predictions for a city for the next 48 hours, per hour-- * Ending the url with "forecast.xml" will give predictions for 9 days, per 6 hours slices.-- Search for your location in https://www.yr.no/-- When found, add forecast.xml or forecast_hour_by_hour.xml to the url-- -- Don't run the script more that once per hour, or 4 times a day for the 6h forecast. Yr.no web admins will certainly thank you for that.-- (no they won't, but they won't curse you for polling their servers every minutes either, which is a total waste of time/bandwidth).-- Previsions for the next hour (or 6h if the url ends with forecast.xml) would be contained in:-- forecast[1].symbol "Partly cloudy"-- forecast[1].icon "03n" (available at https://hjelp.yr.no/hc/en-us/articles/203786121-Weather-symbols-on-Yr) -- forecast[1].precipitation [mm]-- forecast[1].wind_direction "SSW", "E", ...-- forecast[1].wind_speed [m/s]-- forecast[1].temperature [°C]-- forecast[1].pressure [hPa]-- ld_minTemp [°C] Min temperature for the next day -- ld_maxTemp [°C] Max temperature for the next day-- lt_tomorrow What the next day is-- Next hour forecast would be in forecast[2].symbol-- and so on-------------------------------------------------------------------------------------------------------------------------------forecast = {}
----------------------------------------------------------------- Functions---------------------------------------------------------------functionparsetag(parser, tag, attributes)
iftag == 'time'thentable.insert(forecast, {})
forecast[ #forecast ].from = attributes.fromelseiftag == 'symbol'thenforecast[ #forecast ].symbol = attributes.nameforecast[ #forecast ].icon = attributes.varelseiftag == 'precipitation'thenforecast[ #forecast ].precipitation = attributes.valueelseiftag == 'windDirection'thenforecast[ #forecast ].wind_direction = attributes.codeelseiftag == 'windSpeed'thenforecast[ #forecast ].wind_speed = attributes.mpselseiftag == 'temperature'thenforecast[ #forecast ].temperature = attributes.valueelseiftag == 'pressure'thenforecast[ #forecast ].pressure = attributes.valueendend-------------------------------functionyrno_fetch()
ld_minTemp=0ld_maxTemp=0next_day={}
-- local url = 'https://www.yr.no/place/Belgium/Wallonia/Marche-lez-%C3%89caussinnes/forecast.xml'localurl = 'http://www.yr.no/place/Belgium/Wallonia/Marche-lez-%C3%89caussinnes/forecast_hour_by_hour.xml'localdata, err = socket.http.request(url)
ifdatathenrequire('lxp').new({
StartElement = parsetag
}):parse(data)
-- log(forecast)elsealert('Fetch failed: ' .. tostring(err))
return1endll_tomorrow = os.time()+24*3600-- tomorrow as longlt_tomorrow = os.date("*t",ll_tomorrow) -- tomorrow as table for use if forecast_write--gets the date of tomorrowlocalls_match = os.date("%Y--%m--%d",ll_tomorrow)
forindex, valueinipairs(forecast) doif (value.from:match("^"..ls_match)) thenlocalld_temp=tonumber(value.temperature)
if (ld_minTemp == nil) thenld_minTemp=ld_tempendif (ld_maxTemp == nil) thenld_maxTemp=ld_tempendif (ld_temp<ld_minTemporindex==1) thenld_minTemp=ld_tempendif (ld_temp>ld_maxTemporindex==1) thenld_maxTemp=ld_tempendendendreturn0end-------------------------------------------- Main code------------------------------------------ifyrno_fetch() then-- write the data to the bus, or do something else with it-- If the fetch fails, we do nothing.--log(ld_minTemp, ld_maxTemp, lt_tomorrow, forecast[1].symbol, forecast[1].icon, forecast[1].precipitation, forecast[1].wind_direction, --forecast[1].wind_speed, forecast[1].temperature, forecast[1].pressure)--grp.write('1/1/12', ld_minTemp, dt.float16)--grp.write('1/1/13', ld_maxTemp, dt.float16)--grp.write('1/1/14', lt_tomorrow, dt.date)--grp.write('1/1/15', forecast[1].symbol)--grp.write('1/1/16', forecast[1].icon)--grp.write('1/1/17', forecast[1].precipitation)--grp.write('1/1/18', forecast[1].wind_direction)--grp.write('1/1/19', forecast[1].wind_speed)--grp.write('1/1/20', forecast[1].temperature)--grp.write('1/1/21', forecast[1].pressure)end
Hi,
Here is a small contribution from me and others (mostly others in fact).
The script fetches the weather forecast from Yr.no
I've put together some of the previous scripts, and removedsome functions and correct the error handling.
I am not a big fan of using functions only once. I find it makes the code less readable because you have to jump all over the place when you read it.
There is also a description at the beginning of the code explaining how to use it.