2 # -*- coding: iso-8859-15 -*-
4 RS = 8314.3 # J/(kmol*K) universelle Gaskonstante
5 MW = 18.016 # kg/kmol Molekulargewicht des Wasserdampfes
9 API_ID="41ff32c10636d35b4c7a46000cb1a6a1"
14 # Sättigungsdampfdruck in hPa
15 def calc_saturation_vapor_pressure(temp_c):
23 return 6.1078 * 10**((a*temp_c)/(b+temp_c))
26 # https://www.wetterochs.de/wetter/feuchte.html
27 def calc_humidity_abs(temp_c, humdity_rel):
28 temp_k = temp_c + 273.15
31 SDD = calc_saturation_vapor_pressure(temp_c)
32 DD = humdity_rel/100.0 * SDD
33 humidity_abs = 10**5 * MW/RS * DD/temp_k
37 def calc_humidity_rel(temp_c, humidity_abs):
38 temp_k = temp_c + 273.15
39 SDD = calc_saturation_vapor_pressure(temp_c)
40 DD = humidity_abs*temp_k * RS / (10**5*MW)
42 humdity_rel = DD/SDD*100
45 def get_weather_current():
46 query = urllib.urlencode({'id': STATION, 'APPID': API_ID, 'lang': 'de'})
47 url = "http://api.openweathermap.org/data/2.5/weather?units=metric&%s" % query
48 response = urllib.urlopen(url)
49 results = response.read()
50 return json.loads(results)
52 def check_ventilate(temp_indoor, humdity_rel_indoor):
53 dWeatherCurrent = get_weather_current()
54 temp_outdoor = dWeatherCurrent["main"]["temp"]
55 humdity_rel_outdoor = dWeatherCurrent["main"]["humidity"]
57 humdity_abs_indoor = calc_humidity_abs(temp_indoor, humdity_rel_indoor)
58 humdity_abs_outdoor = calc_humidity_abs(temp_outdoor, humdity_rel_outdoor)
60 print "Wassergehalt Innen: %.2f, Außen: %.2f" % (humdity_abs_indoor, humdity_abs_outdoor)
61 return humdity_abs_indoor - humdity_abs_outdoor
64 if __name__ == "__main__":
65 check_ventilate(21, 50)