Fetch Yahoo weather forecast
Example: Fetch Yahoo weather forecast
KNX specific configuration in Logic Machine
- Connect to Logic Machine (Logic Machine) with default access parameters (IP: 192.168.0.10; login/password: admin/admin)

Create “Weather data Yahoo” resident script
- In scripting tab click on the Resident button, then Add new script. In this example the script will be run every minute

- After you have saved the script, click on the icon in Editor column to enter into scripting redactor. The script is fetching 5 variables from Yahoo for Riga city – current temperature, current condition, forecast condition for tomorrow, forecast min and max temperatures for tomorrow, wind speed, wind direction and other parameters – and storing them into KNX group addresses.
- require('json')
- require('socket.http')
- socket.http.TIMEOUT = 5
- local city = 854823
- local data = socket.http.request('https://openrb.com/weather/?w=' .. city)
- if not data then
- alert('Weather: cannot fetch data')
- return
- end
- data = json.pdecode(data)
- if not data then
- alert('Weather: cannot parse data')
- return
- end
- -- current condition and temperature
- grp.write('5/1/1', data.current.text, dt.string)
- grp.write('5/1/2', data.current.temp, dt.float16)
- -- forecast for today
- grp.write('5/1/3', data.today.text, dt.string)
- grp.write('5/1/4', data.today.low, dt.float16)
- grp.write('5/1/5', data.today.high, dt.float16)
- -- forecast for tomorrow
- grp.write('5/1/6', data.tomorrow.text, dt.string)
- grp.write('5/1/7', data.tomorrow.low, dt.float16)
- grp.write('5/1/8', data.tomorrow.high, dt.float16)
- grp.write('5/1/9', data.wind.chill, dt.float16)
- grp.write('5/1/10', data.wind.direction, dt.angle)
- grp.write('5/1/11', data.wind.speed, dt.float16)
- grp.write('5/1/12', data.atmosphere.humidity, dt.scale)
- grp.write('5/1/13', data.atmosphere.visibility, dt.float16)
- grp.write('5/1/14', data.atmosphere.pressure, dt.float16)
- grp.write('5/1/15', data.atmosphere.rising, dt.bool)
- grp.write('5/1/16', data.astronomy.sunrise , dt.string)
- grp.write('5/1/17', data.astronomy.sunset, dt.string)
- After first time the script is run the new group addresses are added (if not added before) into Objects menu. You can set the respective names for these objects.

- You can add these objects into your visualization map with respective icons. Or you can use these objects to preset HVAC system accordingly to weather.
