naofireblade / homebridge-weather-plus

A comprehensive weather plugin for homebridge.
MIT License
311 stars 61 forks source link

Additional API for Weewx #219

Closed CHAMLEX closed 2 years ago

CHAMLEX commented 2 years ago

In reference to #217 and #70 an additional API for Weewx weather integration was added. I also added a sample JSON responese for testing.

naofireblade commented 2 years ago

Hi thanks for your PR! I cannot test this at the moment but as it seems not to break any existing functionality, I will gladly merge it. Could you provide some instructions how to use this in the readme?

CHAMLEX commented 2 years ago

Weewx

Weewx is an open source software for your weather station monitoring that can be found (here), to utilize this plugin you need to have the following extension that create a JSON input that can be found here. Once that is installed a JSON response needs to be created using the following template that creates a JSON file on your server which can be created by adding a new file called YOUR_FILE_NAME_HERE.json.tmpl. and adding it to the skin.conf file.

{
    "observations":[
    {
        "stationID": "$station.location",
        "softwareType": "weewx $station.version",
        "realtimeFrequency": "$current.interval",
        #if $current.radiation.has_data
        "solarRadiation": $current.radiation.raw,
        #end if
        #if $current.rain.raw > 0
        "rainbool": true,
        #else
        "rainbool": false,
        #end if
        "lon": $station.stn_info.longitude_f,
        "epoch": $current.dateTime.raw,
        "lat": $station.stn_info.latitude_f,
        #if $current.UV.has_data
        "uv": $current.UV,
        #end if
        #if $current.windDir.has_data
        "winddir": $current.windDir.raw,
        #end if
        #if $current.outHumidity.has_data
        "humidity": $current.outHumidity.raw,
        #end if
        #if $current.o3.has_data
        "o3": $current.o3.raw
        #end if
        "imperial": {
                        #if $current.outTemp.has_data
                        "temp": $current.outTemp.degree_F.raw,
                        #end if
                        #if $day.outTemp.has_data
                        "maxtemp": $day.outTemp.max.degree_F.raw,
                        "mintemp": $day.outTemp.min.degree_F.raw,
                        #end if
                        #if $current.appTemp.has_data
                        "apptemp": $current.appTemp.degree_F.raw,
                        #end if
                        #if $current.dewpoint.has_data
                        "dewpt": $current.dewpoint.degree_F.raw,
                        #end if
                        #if $current.windSpeed.has_data
                        "windSpeed": $current.windSpeed.mile_per_hour.raw,
                        #end if
                        #if $current.windGust.has_data
                        "windGust": $current.windGust.mile_per_hour.raw,
                        #end if
                        #if $current.barometer.has_data
                        "pressure": $current.barometer.inHg.raw,
                        #end if
                        #if $hour.rain.has_data
                        "precip1h": $hour($hours_ago=1).rain.sum.inch.raw,
                        #end if
                        #if $current.rainRate.has_data
                        "precipRate": $current.rainRate.inch_per_hour.raw,
                        #end if
                        #if $day.rain.has_data
                        "rainday": $day.rain.sum.inch.raw
                        #end if
        },
        "metric": {
                        #if $current.outTemp.has_data
                        "temp": $current.outTemp.degree_C.raw,
                        #end if
                        #if $day.outTemp.has_data
                        "maxtemp": $day.outTemp.max.degree_C.raw,
                        "mintemp": $day.outTemp.min.degree_C.raw,
                        #end if
                        #if $current.appTemp.has_data
                        "apptemp": $current.appTemp.degree_C.raw,
                        #end if
                        #if $current.dewpoint.has_data
                        "dewpt": $current.dewpoint.degree_C.raw,
                        #end if
                        #if $current.windSpeed.has_data
                        "windSpeed": $current.windSpeed.km_per_hour.raw,
                        #end if
                        #if $current.windGust.has_data
                        "windGust": $current.windGust.km_per_hour.raw,
                        #end if
                        #if $current.barometer.has_data
                        "pressure": $current.barometer.mbar.raw,
                        #end if
                        #if $hour.rain.has_data
                        "precip1h": $hour($hours_ago=1).rain.sum.mm.raw,
                        #end if
                        #if $current.rainRate.has_data
                        "precipRate": $current.rainRate.mm_per_hour.raw,
                        #end if
                        #if $day.rain.has_data
                        "rainday": $day.rain.sum.mm.raw
                        #end if
        },
        "metric_si": {
                        #if $current.outTemp.has_data
                        "temp": $current.outTemp.degree_C.raw,
                        #end if
                        #if $day.outTemp.has_data
                        "maxtemp": $day.outTemp.max.degree_C.raw,
                        "mintemp": $day.outTemp.min.degree_C.raw,
                        #end if
                        #if $current.appTemp.has_data
                        "apptemp": $current.appTemp.degree_C.raw,
                        #end if
                        #if $current.dewpoint.has_data
                        "dewpt": $current.dewpoint.degree_C.raw,
                        #end if
                        #if $current.windSpeed.has_data
                        "windSpeed": $current.windSpeed.meter_per_second.raw,
                        #end if
                        #if $current.windGust.has_data
                        "windGust": $current.windGust.meter_per_second.raw,
                        #end if
                        #if $current.barometer.has_data
                        "pressure": $current.barometer.mbar.raw,
                        #end if
                        #if $hour.rain.has_data
                        "precip1h": $hour($hours_ago=1).rain.sum.mm.raw,
                        #end if
                        #if $current.rainRate.has_data
                        "precipRate": $current.rainRate.mm_per_hour.raw,
                        #end if
                        #if $day.rain.has_data
                        "rainday": $day.rain.sum.mm.raw
                        #end if
        },
        "uk_hybrid": {
                        #if $current.outTemp.has_data
                        "temp": $current.outTemp.degree_C.raw,
                        #end if
                        #if $day.outTemp.has_data
                        "maxtemp": $day.outTemp.max.degree_C.raw,
                        "mintemp": $day.outTemp.min.degree_C.raw,
                        #end if
                        #if $current.appTemp.has_data
                        "apptemp": $current.appTemp.degree_C.raw,
                        #end if
                        #if $current.dewpoint.has_data
                        "dewpt": $current.dewpoint.degree_C.raw,
                        #end if
                        #if $current.windSpeed.has_data
                        "windSpeed": $current.windSpeed.mile_per_hour.raw,
                        #end if
                        #if $current.windGust.has_data
                        "windGust": $current.windGust.mile_per_hour.raw,
                        #end if
                        #if $current.barometer.has_data
                        "pressure": $current.barometer.mbar.raw,
                        #end if
                        #if $hour.rain.has_data
                        "precip1h": $hour($hours_ago=1).rain.sum.mm.raw,
                        #end if
                        #if $current.rainRate.has_data
                        "precipRate": $current.rainRate.mm_per_hour.raw,
                        #end if
                        #if $day.rain.has_data
                        "rainday": $day.rain.sum.mm.raw
                        #end if
        }
    }
    ]
} 

key
Weewx doesnt use a key but uses the key as the location for your JSON file. Just place the URL in the key and the app will use that to pull the json location.

locationCity
Used to indicate Weewx version. The homekit plugin requires an location field that is used to run. It technically can be any text you want but I just have added the Current Weewx versin..

"platforms": [
    {
        "platform": "WeatherPlus",
        "service": "weatherunderground",
        "key": "http://weewx.lan/homekit.json",
        "locationCity": "V.4.3.1"
    }
]
CHAMLEX commented 2 years ago

Feel free to edit out the comments in the Weewx API that includes the Weewx info for the template since it's covered here and also the sample Weewx JSON response probably doesn't need to be added.

warenext commented 2 years ago

Just curious... in the WeeWX JSON, characteristics which have units are broken out into arrays grouped according to the measurement system used. I followed your lead in my contribution, but I was wondering why it's that way. Is it because WeeWX does the conversions itself, and all those values are already available? Or because the developer of weewx-json handled it that that way? The homebridge-weather-plus code has functions in characteristics.js for doing the unit conversions, and I think providing only one system of units in the JSON input and having weather-plus do the conversions would generally be more preferable.

CHAMLEX commented 2 years ago

I based the formatting off of the JSON response and the api reader on the Weather Underground JSON response and just included all the units that it would respond with. You could format it to only use metric_si units, but I planned on using this JSON response with another application so I wanted to include the other units as well. It also helped me to make sure I had everything coded correctly since I could make sure I was getting the correct units.

ituri commented 2 years ago

Really looking forward to this feature! 😊

sinabuddy commented 2 years ago

Today, i have tried to install and connect to weewx. weewx create the json-File. But the homebridge shows no values. homebridge shows an error:

[10.5.2022, 18:34:03] [WeatherPlus] Error retrieving weather report and forecast [10.5.2022, 18:34:03] [WeatherPlus] Error Message: Error: [ { "error": { "code": "CDN-0001", "message": "Invalid apiKey." } } ]

homebridge config: { "platform": "WeatherPlus", "service": "weatherunderground", "key": "http://192.168,0.30/weewx/test.json", "locationCity": "V.4.8.0" }

the "test.json" can i open in the browser: { observations:[ { stationID: "my Station", softwareType: "weewx 4.8.0", realtimeFrequency: "10,0 minutes", solarRadiation: 95.0, rainbool: "No", lon: 9.000, epoch: 1652202600, lat: 45.000, uv: 0,6, winddir: 0.0, humidity: 52.0, ...

the json seems to be ok, it contains values.

image

any ideas?am I too early? or too fast? greatings

CHAMLEX commented 2 years ago

I don't believe this branch/edits has been incorporated yet.

naofireblade commented 2 years ago

Oh yes, I really need to merge and create a new release. Will do it this week.