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)
Logic machine visualization main screen

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
Yahoo weather resident script logic machine
  • 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 – and storing them into KNX group addresses.
Yahoo weather script logic machine
  • 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.
Yahoo weather 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.
Logic Machine visualization Yahoo weather
  1. require('json')
  2.  
  3. local city = 854823
  4. local cmd, data, forecast
  5.  
  6. cmd = 'wget -q -O - "http://weather.yahooapis.com/forecastjson?w=' .. city .. '&u=c" 2>/dev/null'
  7. data = io.readproc(cmd)
  8. if not data then
  9. alert('Weather: cannot get data')
  10. return false
  11. end
  12.  
  13. data = json.pdecode(data)
  14. if not data then
  15. alert('Weather: cannot parse data')
  16. return false
  17. end
  18.  
  19. grp.write('5/1/1', data.condition.text, dt.string)
  20. grp.write('5/1/2', data.condition.temperature, dt.float16)
  21.  
  22. forecast = data.forecast[2]
  23. grp.write('5/1/3', forecast.condition, dt.string)
  24. grp.write('5/1/4', forecast.low_temperature, dt.float16)
  25. grp.write('5/1/5', forecast.high_temperature, dt.float16)