Hi all, for anyone looking to use the ECOWITT output type. Here is a php that performs well. It’s just a modification of @binderth’s amazing code.
You’ll need to use this if you need data such as additional sensors and battery data, which aren’t supported by the wunderground format.
I’ve also included a corresponding items file. I have one additional sensor on CH2. You can add extras as you have configured.
I’ve also included a handy function at the top, comment this back in to troubleshoot and see the values your php file is receiving.
<?php
// Code to log your Ecowitt output to a file for exploration and troubleshooting.
// You'll need to create the directory /var/log/weather/ and give it permissions.
// $date = date_create();
// $handle = fopen("/var/log/weather/" . date_timestamp_get($date), "w");
// $result = print_r($_POST, true);
// print_r(error_get_last());
// fwrite($handle, $result);
// fclose($handle);
// Beispiel von Wetteratation
// 192.168.0.119 - - [12/Jun/2020:20:29:37 +0000] "GET /wetterstation.php?ID=1&PASSWORD=1&indoortempf=81.1&tempf=70.5&dewptf=52.7&windchillf=70.5&indoorhumidity=40&humidity=53&windspeedmph=1.6&windgustmph=2.2&winddir=79&absbaromin=29.064&baromin=29.903&rainin=0.000&dailyrainin=0.000&weeklyrainin=0.000&monthlyrainin=0.000&solarradiation=0.00&UV=0&dateutc=2020-06-12%2020:29:37&softwaretype=EasyWeatherV1.5.0&action=updateraw&realtime=1&rtfreq=5 HTTP/1.0" 200 913 "-" "-"
$weatherprefix = "Weatherstation_"; // if you have a prefix in your OH2 items configuration
// resends all GET-Values directly to OH2 API
foreach ($_POST as $key => $value) {
// looking for suffixes and redirecting them
/* Weatherunderground format looks like this:
* ID ID (configuratble in the App)
* PASSWORD KEY (configurable in the App)
* indoortempf in Fahrenheit
* windchillf in Fahrenheit
* indoorhumidity in percent
* humidity in pfpro_cleanup
* windspeedmph in mp/h
* windgustmph in mp/h
* winddir in degrees
* absbaromin in inch of mercury
* baromin in inch of mercury
* rainin in inch
* dailyrainin in inch
* weeklyrainin in inch
* monthlyrainin in inch
* solarradiation in W/m2
* UV in index (0 - 11)
* dateutc current date (UTC)
* softwaretype used software
* action usually "updateraw"
* realtime using real-time updates (0/1)
* rtfreq update frequency (configurable in the App)
as seen here, with the last character(s) of a attribute you can tell, which unit is used
*/
switch ($key) {
case "tempinf":
case "tempf":
case "temp1f":
case "temp2f":
case "temp3f":
case "temp4f":
case "temp5f":
case "temp6f":
case "temp7f":
case "temp8f":
// case ""
// unit is in Fahrenheit (remove "f")
if(f2c($value) < -40) { //Filter für unmögliche Werte
sendOH2Command($weatherprefix . "error", "Filter: " . $key . "=" . $value . "(" . f2c($value) . "°C)");
}
else {
sendOH2Command($weatherprefix.str_replace("f", "", $key), f2c($value));
}
break;
// case "ptf":
// // unit is in Fahrenheit also (remove "f")
// if(f2c($value) > -40) //Filter für unmögliche Werte
// sendOH2Command($weatherprefix.str_replace("ptf", "pt", $key), f2c($value));
// else
// sendOH2Command($weatherprefix . "error", "Filter: " . $key . "=" . $value . "(" . f2c($value) . "°C)");
// break;
// case "llf":
// // unit is in Fahrenheit also (remove "f")
// if(f2c($value) > -40) //Filter für unmögliche Werte
// sendOH2Command($weatherprefix.str_replace("llf", "ll", $key), f2c($value));
// else
// sendOH2Command($weatherprefix . "error", "Filter: " . $key . "=" . $value . "(" . f2c($value) . "°C)");
// break;
case "baromrelin":
case "baromabsin":
// unit is in inHg (remove "min")
sendOH2Command($weatherprefix.str_replace("in", "", $key), inHG2hPa($value));
break;
case "rainratein":
case "eventrainin":
case "hourlyrainin":
case "dailyrainin":
case "weeklyrainin":
case "monthlyrainin":
case "yearlyrainin":
// unit is in inch (remove "in" from end of field)
sendOH2Command($weatherprefix.substr($key, 0, -2), in2mm($value));
break;
case "windspeedmph":
case "windspdmph_avg10m":
case "windgustmph":
case "maxdailygust ":
// unit is in mph (remove "mph")
sendOH2Command($weatherprefix.str_replace("mph", "", $key), mph2kmh($value));
break;
case "utc":
// unit is in UTC
sendOH2Command($weatherprefix.$key, str2UTC($value)."");
break;
default:
// everything else: not a unit, or percent or string
if($value > -1000) //Filter für unmögliche Werte
sendOH2Command($weatherprefix.$key, $value);
else
sendOH2Command($weatherprefix . "error", "Filter: " . $key . " = " . $value);
}
}
function sendOH2Command($item, $data) {
$url = "http://openhabian:8080/rest/items/" . $item;
// $url = "http://localhost:32080/rest/items/" . $item; //geht mit localhost nicht
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'POST',
'content' => '' . $data //http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
function str2UTC($given_value) {
return str_replace(" ", "T", $given_value);
}
function mph2kmh($given_value) {
return '' . round( floatval($given_value) * 1.60934, 1);
}
function in2mm($given_value) {
return '' . round( floatval($given_value) * 25.4, 1);
}
function inHG2hPa($given_value) {
return '' . round( floatval($given_value) * 33.8639 , 1); //1 inHG = 3386,39 Pa, Bespielwert: 29.064 sollte ca 985 sein
}
function f2c($given_value) {
return '' . round( (5.0 / 9 * (floatval($given_value) - 32 )), 1);
}
?>
String Weatherstation_JSON "Weatherstation JSON"
Group Weather "Weather Observations" (All)
// Config Info
// String Weatherstation_PASSKEY "id"
String Weatherstation_PASSKEY "Key / Passsword"
String Weatherstation_stationtype "Software Version"
String Weatherstation_model "Station Model"
DateTime Weatherstation_dateutc "Date" <temperature> (gWeather, Weather)
String Weatherstation_softwaretype "Software" <temperature> (gWeather, Weather)
String Weatherstation_action "WeatherAction" <temperature> (gWeather, Weather)
String Weatherstation_realtime "Realtime" <temperature> (gWeather, Weather)
String Weatherstation_rtfreq "Updatefrequency" <temperature> (gWeather, Weather)
// Temperature
Number:Temperature Weatherstation_tempin "Indoor Temperature [%.1f %unit%]" <temperature> (gWeatherTemp, Weather)
Number:Temperature Weatherstation_temp "Outdoor Temperature [%.1f %unit%]" <temperature> (gWeatherTemp, Weather)
Number:Temperature Weatherstation_dewpt "Dew Point [%.1f %unit%]" <temperature> (gWeatherTemp, Weather)
Number:Temperature Weatherstation_windchill "Windchill [%.1f %unit%]" <temperature> (gWeatherTemp, Weather)
Number:Temperature Weatherstation_temp2 "Greenhouse Temp [%.1f %unit%]" <temperature> (gWeatherTemp, Weather)
// Barometer
Number:Pressure Weatherstation_baromrel "Barometer min [%.1f %unit%]" <temperature> (gWeatherPressure, Weather)
Number:Pressure Weatherstation_baromabs "Abs. Barometer min [%.1f %unit%]" <temperature> (gWeatherPressure, Weather)
// Rain
Number:Length Weatherstation_rainrate "Rain [%.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_eventrain "Rain Event [%.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_hourlyrain "Rain Hourly [%.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_dailyrain "Rain Daily [%.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_weeklyrain "Rain Weekly %.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_monthlyrain "Rain Monthly [%.1f mm]" <temperature> (gWeatherHeight, Weather)
Number:Length Weatherstation_yearlyrain "Rain Yearly [%.1f mm]" <temperature> (gWeatherHeight, Weather)
// Wind
String Weatherstation_winddir "Wind Direction" <temperature> (gWeather, Weather)
String Weatherstation_winddir_avg10m "Wind Speed [%.1f %unit%]" <temperature> (gWeatherSpeed, Weather)
Number:Speed Weatherstation_windspeed "Wind Speed [%.1f %unit%]" <temperature> (gWeatherSpeed, Weather)
Number:Speed Weatherstation_windspd_avg10m "Wind Speed (Ave 10 mins) [%.1f %unit%]" <temperature> (gWeatherSpeed, Weather)
Number:Speed Weatherstation_windgust "Wing Gust [%.1f %unit%]" <temperature> (gWeatherSpeed, Weather)
Number:Speed Weatherstation_maxdailygust "Wing Gust (Max Daily) [%.1f %unit%]" <temperature> (gWeatherSpeed, Weather)
// Humidity
Number Weatherstation_humidity "Outdoor Humidity [%.1f %%]" <temperature> (gWeather, Weather)
Number Weatherstation_humidityin "Indoor Humidity [%.1f %%]" <temperature> (gWeather, Weather)
Number Weatherstation_humidity2 "Greenhouse Humidity [%.1f %%]" <temperature> (gWeather, Weather)
// Solar Info
Number Weatherstation_solarradiation "Solar Radiation [%.1f]" <temperature> (gWeather, Weather)
Number Weatherstation_uv "UV-Index [%.1f]" <temperature> (gWeather, Weather)
//Battery
Number Weatherstation_wh65batt "WH65 Battery" <temperature> (gWeather, Weather)
Number Weatherstation_wh25batt "Indoor Sensor Battery [%.1f]" <temperature> (gWeather, Weather)
Number Weatherstation_batt2 "Greenhouse Sensor Battery[%.1f]" <temperature> (gWeather, Weather)