Outside WiFi weather station "WS3500" and local customized upload (no cloud needed)

shouldn’t be a problem with fputcsv! :wink:

…yes, I’m German, near Augsburg.

Hi,

I was looking for a Weather Station and found this topic.
Thank you very much for sharing!
I’m trying to get this running in docker with Dockerfile:

FROM php:7.2-apache
COPY . /var/www/html
EXPOSE 80
CMD apache2-foreground

If i omit the CMD, the docker container is stopped with:

[mpm_prefork:notice] [pid 1] AH00170: caught SIGWINCH, shutting down gracefully

It runs, and gives the following output on every update

10.0.3.1 - - [11/Jun/2020:20:51:33 +0000] “GET / HTTP/1.1” 200 241 “-” “python-requests/2.18.4”

Is it supposed to look like this?

However nothing happens in openhab (REST API is working, and $url is correct)

Any suggestion how to solve this, please?

Hi,

I have the same problem. The weather station calls the script every 20 seconds, but no values in openhab2. The rest api has tested and was working with this command:

curl -X POST --header “Content-Type: text/plain” --header “Accept: application/json” -d “ON” “http://192.168.xxx.xxx:8080/rest/items/Esszimmerlicht

There were some issues I had to solve:

  1. The Weatherstation was not calling the script, so i set Station ID: 1 and Station Key: 1 in the WS View app. I also forgot to add the “?” in path, so corrected to: /wetterstation.php?
  2. The script wasn’t working, so i tried to do the same request as logged from browser and found that the functions where somehow missing, so I wrote them.

The 10.0.3.1 calls are from something else.

So this is the modified working PHP-file:wetterstation.php.txt (3.6 KB)

1 Like

Thankx @Andreas_Pircher, you’re absolutely right, I somehow managed to not include the functions for calculating the metric values… I just updated the code in my initial post (I rounded on two digits)

And yes, one important thing is to type in the path to the script in the App with the trailing ? at the end, otherwise you won’t get the GET-attributes… (I also just updated the initial screenshot)

I discovered a calculation error in @binderth’s script I was using for over a year now … :slight_smile:
There was a in2cm function, but in Openhab I display mm.
This is the updated version: wetterstation.php.txt (4.4 KB)

1 Like

I’m using it since forever! :wink:
Thanks for spotting it! I’m not sure how that slipped. Perhaps something I configured in OH2 but in OH3 it’s different now… :man_shrugging: anyways: thanks!

Hi all,
Just thinking to order one of these weather stations.
Do you think this script will work with

Or do you have a correct link to one of the compatible stations as I get a few results for WS3500

Thanks in advance

Koen

This is the exact weather station I’m using since - with my script! :wink:

Okay,
Thx for your quick respons. I’m gonna order this one :grinning:

Finally a have some spare time to get this project going.
What would be the easiest straight forward methode of creating this website? webstation or would wordpress maybe easier?

it isn’t a website, you only need an PHP parser. if you’re running a Synology NAS you can use webstation with active PHP of course. or any other PHP-capable webserver… wordpress for pnly this purpuse would be the definition of overkill

Hello to all,

thank you for script it works on my side too.

I only recognized that these two items were not updated:

DateTime				Weatherstation_dateutc			"Uhrzeit"							<temperature>	(gWeather, Wetter)	

Number 					Weatherstation_elev				"Elevation [%.1f]"				<temperature>	(gWeather, Wetter)	

Is it the same on your setup?

@binderth: In the php file I found the “Beispiel von Wetterstation”. How did you read out this example from your weather station? I have no experience with PHP but maybe this script is good starting point for me.

// 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 "-" "-"

first of all, the linked PHP-script in #12 is the starting point:

What the script does is the following:

foreach ($_GET as $key => $value) {

This loops through all GET-parameters, the weather station sends.

	switch (substr($key, -3)) {

this one looks for the las three digits of the key-string (e.g. indoortempf) and converts some units to “the correct” units. :wink:
if there’s no unit, it’s default just sends the value.

function sendOH2Command($item, $data) {

this one sends the value to openHAB via REST API.

So, if you’re missing a value, make sure, you have the corresponding item available in your items, and keep in mind:

$weatherprefix = "Weatherstation_"; // if you have a prefix in your OH2 items configuration
...
endOH2Command($weatherprefix.$key, $value);

so, the item name should bei Weatherstation_elev and the weather station should send a key “elev” and one “dateutc”.
My weather station (EasyWeather-WIFI50DD) sends the “dateutc”, but not “elev”.

Thank this helps me a lot.

You have mentioned that your weather station sends not the “elev” key.

How do you request the data/key from your weather station?
Can I just type in the browser e.g.

http://my_weather_station_ip/getData

I would like to check what my weather stations sends out, maybe the name is not matching.
But I do not know how to read out these information from the weather station

No, you can’t. Please read the thread from the beginning (I know, annoying, if there’s info splattered across).

You have to configure the weather station in the “WS View”-App to call a certain script. It will then do that periodically - you set the seconds in the “upload interval”.

you can

  1. you can check your PHP webserver’s logfile
  2. you can edit the PHP script to write the GET-parameters in a file or something

easiest would be 1. I guess, if you know, where it is.

Also, this is, what my WS3500 aka WIFI50DD sends (Firmware: EasyWeathev1.6.4) - already converted to JSON-format

{
  "ID": "123",
  "PASSWORD": "987",
  "indoortempf": "78.1",
  "tempf": "84.4",
  "dewptf": "56.8",
  "windchillf": "84.4",
  "indoorhumidity": "47",
  "humidity": "39",
  "windspeedmph": "1.8",
  "windgustmph": "3.4",
  "winddir": "165",
  "absbaromin": "28.358",
  "baromin": "30.036",
  "rainin": "0.000",
  "dailyrainin": "0.000",
  "weeklyrainin": "0.000",
  "monthlyrainin": "0.791",
  "solarradiation": "577.79",
  "UV": "5",
  "dateutc": "2022-07-28 13:36:02",
  "softwaretype": "EasyWeatherV1.6.4",
  "action": "updateraw",
  "realtime": "1",
  "rtfreq": "5"
}

Thanks, for your tip.
I have added this to the php file:
My first php code but it works :grinning:

	// write data from weather station into txt file
	$result = array($_GET);
	file_put_contents("weatherstation_data.txt",print_r($result, true));

Here my data:

Array
(
    [0] => Array
        (
            [ID] => XXX
            [PASSWORD] => XXXX
            [tempf] => 87.6
            [humidity] => 37
            [dewptf] => 58.3
            [windchillf] => 87.6
            [winddir] => 280
            [windspeedmph] => 3.80
            [windgustmph] => 5.82
            [rainin] => 0.000
            [dailyrainin] => 0.000
            [weeklyrainin] => 0.000
            [monthlyrainin] => 0.071
            [yearlyrainin] => -9999
            [totalrainin] => 0.071
            [solarradiation] => 225.11
            [UV] => 2
            [indoortempf] => 80.8
            [indoorhumidity] => 43
            [absbaromin] => 29.211
            [baromin] => 29.716
            [lowbatt] => 0
            [dateutc] => now
            [softwaretype] => EasyWeatherPro_V5.0.7
            [action] => updateraw
            [realtime] => 1
            [rtfreq] => 5
        )

)

Here my info regarding the weatherstation Sainlogic WS3500 built 05.2022.
When I look into WSView Plus app the weather station is called "EasyWeatherPro-0FDC2.1
image

We both have no “elev” and my “dateutc” is only a string with now.

I have created my additional data and changed the the Data to String, makes no sense but I get now all data provided by the weather station;-)

Number 					Weatherstation_lowbatt			"Batterie"				<temperature>	(gWeather, Wetter)	
Number:Length 			Weatherstation_yearlyrain		"Niederschlag/Jahr [%.1f mm]"   <rain>	(gWeatherHeight, Wetter)	
**String**  				Weatherstation_dateutc			"Uhrzeit"							<temperature>	(gWeather, Wetter)	

1 Like

I think, your Firmware has an bug with “now” instead of a UTC-timestamp!
other than that, it looks good! And beware of your skills in scripting growing over time using openHAB! :wink:

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)	
1 Like