After running a WS-5500 PWS for a while, I wanted to collect my data in domoticz.
Thanks to the plugin written by Xorfor https://www.domoticz.com/forum/viewtopi ... 65&t=29165 it was a peace of cake
Then i wanted to upload my data to a weather service on the internet, but I am no great fan of wunderground.
After some searching I came across WeatherCloud
So I took the liberty to write a python script for uploading the domoticz gathered data to my virtual device at WeatherCloud.
First you have to register at WeatherCloud to get an ID and a Key, which is needed in the script.
The script runs from cron every 10 minutes (WeatherCloud free account only accepts data every 10 minutes)
Hope someone else can make use of this
Code: Select all
#!/usr/bin/python3
#script to upload weather data from WS-5500 domoticz device to weather cloud
#
import json
import requests
# Settings for the domoticz server
domoticzserver = "192.168.0.31:8880"
def domoticzrequest (url):
response = requests.get(url)
return response.json()
def read_data(sensor):
for i, v in enumerate(json_object["result"]):
if json_object["result"][i]["Name"].lower() == sensor.lower():
data_read = json_object["result"][i]["Data"]
return data_read
def log_to_domoticz(message):
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=addlogmessage&message=" + str(message))
#function to calculate heat index
def heat_index(temp,hum):
fahrenheit = ((temp * 9/5) + 32)
# Creating multiples of 'fahrenheit' & 'hum' values for the coefficients
T2 = pow(fahrenheit, 2)
T3 = pow(fahrenheit, 3)
H2 = pow(hum, 2)
H3 = pow(hum, 3)
C3 = [ 16.923, 0.185212, 5.37941, -0.100254, 0.00941695, 0.00728898, 0.000345372, -0.000814971, 0.0000102102, -0.000038646, 0.0000291583, 0.00000142721, 0.000000197483, -0.0000000218429, 0.000000000843296, -0.0000000000481975]
heatindex3 = C3[0] + (C3[1] * fahrenheit) + (C3[2] * hum) + (C3[3] * fahrenheit * hum) + (C3[4] * T2) + (C3[5] * H2) + (C3[6] * T2 * hum) + (C3[7] * fahrenheit * H2) + (C3[8] * T2 * H2) + (C3[9] * T3) + (C3[10] * H3) + (C3[11] * T3 * hum) + (C3[12] * fahrenheit * H3) + (C3[13] * T3 * H2) + (C3[14] * T2 * H3) + (C3[15] * T3 * H3)
heatindex = (round(((heatindex3 - 32) * 5/9), 0))
return heatindex
#fetch domoticz data
json_object = domoticzrequest("http://" + domoticzserver + "/json.htm?type=devices&filter=all&used=true&order=Name")
#calculate weather data en convert to float for easy calculation.
# temperature / humidity / barometer
arr_thb_data = read_data("WS-5500 - THB").split(",")
arr_temp = arr_thb_data[0].split(" ")
arr_hum = arr_thb_data[1].split(" ")
arr_bar = arr_thb_data[2].split(" ")
humidity = float(arr_hum[1])
ambient_temp = float(arr_temp[0])
pressure = float(arr_bar[1])
# dew point
arr_dewpoint = read_data("WS-5500 - Dew point").split(" ")
dewpoint = float(arr_dewpoint[0])
# rainfall past day
arr_rain_daily = read_data("WS-5500 - Rain").split(";")
rainin = float(arr_rain_daily[0])
# rainfall past hour
arr_rain_in = read_data("WS-5500 - Rain rate").split(" ")
rainrate = float(arr_rain_in[0])
# wind
arr_winddirection = read_data("WS-5500 - Wind direction").split(" ")
wind_direction = int(float(arr_winddirection[0]))
arr_windchill = read_data("WS-5500 - Chill").split(" ")
wind_chill = float(arr_windchill[0])
arr_wind_speed = read_data("WS-5500 - Wind speed").split(" ")
wind_speed = float(arr_wind_speed[0])
arr_wind_gust = read_data("WS-5500 - Gust").split(" ")
wind_gust = float(arr_wind_gust[0])
# uv index
arr_uv = read_data("WS-5500 - UVI").split(" ")
uv = float(arr_uv[0])
# solar radiation
arr_solar = read_data("WS-5500 - Solar radiation").split(" ")
solar = float(arr_solar[0])
# compose url for uplad
#http://api.weathercloud.net/set/wid/xxxxxxx/key/xxxxxxxxxxxxx/temp/210/tempin/233/chill/214/heat/247/hum/33/humin/29/wspd/30/wspdhi/30/wspdavg/21/wdir/271/wdiravg/256/bar/10175/rain/0/solarrad/1630/uvi/ 5/ver/1.2/type/201
#http://api.weathercloud.net/get/wid/xxxxxxxx/key/xxxxxxxxxxx/temp/48/tempin/233/dewin/110/chill/0/heat/48/dew/15/hum/79/humin/46/wspd/5/wspdhi/10/wspdavg/7/wdir/152/wdiravg/149/bar/10128/rain/0.0/solarrad/0/uvi/0/rainrate/0/thw/48/et/0/ver/1.7/type/201
WCurl = "http://api.weathercloud.net/set/wid"
WC_Id = "/xxxxxxxxxxxxxxxxx" #replace all x with you personal ID
WC_key = "/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" #replace all y with you personal key
last = "/ver/1.2/type/201"
p= requests.get(
WCurl +
WC_Id +
"/key" +
WC_key +
"/temp/" + str(ambient_temp * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/bar/" + str(int(pressure) * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/dew/" + str(dewpoint * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/hum/" + str(humidity) +
"/wspd/" + str(wind_speed * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/wdir/" + str(wind_direction) +
"/chill/" + str(wind_chill * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/heat/" + str(heat_index(ambient_temp,humidity)) +
"/wspdhi/" + str(wind_gust + 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/rain/" + str(rainin) +
"/rainrate/" + str(rainrate) +
"/solarrad/" + str(solar * 10) + # Weathercloud seems to divide the delivered data by 10, so we first mutliply them before delivering.
"/uvi/" + str(uv) +
last)
#print some data to check if values are ok.
print(WCurl + WC_Id + "/key" + WC_key + "/temp/" + str(ambient_temp * 10) + "/bar/" + str(int(pressure) * 10) + "/dew/" + str(dewpoint * 10) + "/hum/" + str(humidity) + "/wspd/" + str(wind_speed * 10) + "/wdir/" + str(wind_direction) + "/chill/" + str(wind_chill * 10) + "/heat/" + str(heat_index(ambient_temp,humidity)) + "/wspdhi/" + str(wind_gust * 10) + "/rain/" + str(rainin) + "/rainrate/" + str(rainrate) + "/solarrad/" + str(solar * 10) + "/uvi/" + str(uv) + last)
print("Received " + str(p.status_code) + " " + str(p.text))