Hello mstrandbo and Cumulus community,
I recently changed my PWS. My new one is a Bresser 7-in-1 wifi. As yours, my PWS is not in the supported devices list of Cumulus MX.
Thus I added it to WU (stationID = ILESMA30) and made a short python3 script to convert the api.weather.com JSON file to an easyweatherplus.dat file.
My Cumulus MX is installed on a Raspberry. I set crontab to execute my script every minute (* * * * *) to update the dat file.
Here is the py script :
Code: Select all
# -*- coding: utf-8 -*-
# script pour extraire les valeurs de
# https://api.weather.com/v2/pws/observations/current?stationId=***&format=json&units=m&apiKey=*****
from urllib.request import urlopen
import json
rose = ["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"]
f = urlopen("https://api.weather.com/v2/pws/observations/current?stationId=ILESMA30&format=json&units=m&apiKey=#####
chain = json.load(f)
#codeStation = chain["observations"][0]["stationID"]
chainDateTime = chain["observations"][0]["obsTimeLocal"]
chainDateTime = chainDateTime.replace(" ",",")
outdoorHum = chain["observations"][0]["humidity"]
outdoorTemp = chain["observations"][0]["metric"]["temp"]
dewPoint = chain["observations"][0]["metric"]["dewpt"] # point de rosée
windChill = chain["observations"][0]["metric"]["windChill"] # refroidissement éolien
pressure = chain["observations"][0]["metric"]["pressure"]
windAverage = chain["observations"][0]["metric"]["windSpeed"] # vitesse moyenne du vent
windGust = chain["observations"][0]["metric"]["windGust"] # rafale de vent # Cumulus displays huge unconsistant windgust far from windGust from this JSON. Why ?!???
windDirection = chain["observations"][0]["winddir"] # en degrés
windDirectionText = rose[round(int(windDirection)/22.5)]
rainTotal = chain["observations"][0]["metric"]["precipTotal"] # pluie depuis 00:00 (correct? to be verified)
rainLastHour = chain["observations"][0]["metric"]["precipRate"] # pluie / heure = taux de pluie (correct? to be verified)
lightReading = int(126.6 * float(chain["observations"][0]["solarRadiation"])) # en lux (=lumen/m2)
UVindex = chain["observations"][0]["uv"]
easyweatherplus = "0,0,0," + chainDateTime + ",0,0,0," + str(outdoorHum) + "," + str(outdoorTemp) + "," + str(dewPoint) + "," + str(windChill) + ",0," + str(pressure) + "," + str(windAverage) + ",0," + str(windGust) + ",0," + str(windDirection) + "," + windDirectionText + ",0,0,0," + str(rainLastHour) + ",0,0,0," + str(rainTotal) + "," + str(lightReading) + "," + str(UVindex)
#print (easyweatherplus)
f = open("/home/pi/CumulusMX/easyweatherplus.dat", "w")
f.write(easyweatherplus)
f.close()
You just have to:
- change the code line starting from "f = urlopen..." with your station ID and API key
- crontab -e to edit the cron tasks list. Add the new line " * * * * * python3 /<path>/<name of the py script> "
- configure the station settings in Cumulus MX. 1) in General Settings: Station type: EasyWether, Log interval: 1 minute ; 2) in EasyWeather File Settings: the full path and name of the py file.
- if your PWS can measure light intensity and UV level, check Extra sensors in Common Options.
Cheers
vr34
EDIT: script Python corrected. Post updated 2022/11/03. Everything ok excepted windgust