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

I just installed my “Sainslogic Wifi” weather station, which is WS3500 hardware and has therefore the automated upload to Weather Underground, ecowitt.net, Weathercloud, WeatherObservationWebsite, and “Customized” Upload:


For installation I used the App “WS View”, which let to connecting the WS3500 to my WiFi and uploading all sensor information to WU…

Has anyone succeeded in using the customized upload locally? I inserted the IP of a local webserver running PHP and tried to POST all incoming GETs and POSTs on “wetterstation.php” to OpenHAB REST API, but the station uploads to weather underground, but not on my local webserver.

OK - I’ll answer myself! :wink:
After a while, the updates came in. So now you don’t have to update WeatherUnderground (or similar cloud services) and re-import your own data, but you can send the data to a server of your liking.

So, first, the configuration above needed a bit of tweaking:

  • ServerIP/Hostname: fill in your local Webserver
  • Path: Chose the path to your Webserver-Import script and add a “?” at the end
  • Station ID: if you’d like you can fill in some ID
  • Station Ke: if you’d like you can fill in some Code/Key/Password
  • Port: obviously the port of your webserver is running
  • Upload Interval: minimum 16 secs, maximum some five minutes or so

Now, the WS3500 will call the webserver script in your given interval and put the values via GET into your script.

in my case, I use my Synology Webserver running PHP, so the PHP script looks like this:

<?
// prefix for your OH2-items
$weatherprefix = "WeatherStation_";

// all GETs get redirected to the OH2 API
foreach ($_GET as $key => $value) {
	sendOH2Command($weatherprefix.$key, $value);	
}

// function to POST the item's value to OH2 API (fill in your OH2-IP)
function sendOH2Command($item, $data) {
  $url = "http://192.168.xxx.xxx:8080/rest/items/".$item;

  $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;
}
?> 

That’s it, now, everytime your PHP script is called, the GET-values get send to your OH2 API with the prefix.

For me, my .items looks like this:

String WeatherBinder_ID				"ID"		
String WeatherBinder_PASSWORD		"PWD"		
Number WeatherBinder_indoortempf	"Innen Temperature [%.1f °F]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_tempf			"Aussen Temperature [%.1f °F]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_dewptf			"Taupunkt [%.1f °F]"					<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_windchillf		"Windchill [%.1f °F]"					<temperature>	(gWeatherTemp, Wetterstation)
Number WeatherBinder_indoorhumidity	"Innen Feuchtigkeit [%.1f %]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_humidity		"Außen Feuchtigkeit [%.1f %]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_windspeedmph	"Windgeschwindigkeit [%.1f mph]"		<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_windgustmph	"Windböen [%.1f mph]"					<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_winddir		"Windrichtung"							<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_absbaromin		"Abs. Luftdruck min [%.1f hP]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_baromin		"Luftdruck min [%.1f hP]"				<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_rainin			"Niederschlag [%.1f inch]"				<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_dailyrainin	"Niederschlag/Tag [%.1f inch]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_weeklyrainin	"Niederschlag/Woche %.1f inch]"			<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_monthlyrainin	"Niederschlag/Monata [%.1f inch]"		<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_solarradiation	"Solareintrag [%.1f]"					<temperature>	(gWeatherTemp, Wetterstation)	
Number WeatherBinder_UV				"UV-Index [%.1f]"						<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_dateutc		"Uhrzeit"								<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_softwaretype	"Software"								<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_action			"Wetteraktion"							<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_realtime		"Abs. Luftdruck min [%.1f hP]"			<temperature>	(gWeatherTemp, Wetterstation)	
String WeatherBinder_rtfreq			"Updatefrequenz"						<temperature>	(gWeatherTemp, Wetterstation)	

so, for me, the temperature is in the wrong format (°F) and the wind speed also (mph), I need the correct formats like °C and kmh, so I have to figure out, if I can either tell the WS3500 to send the correct ones or I can tell OH2 to automatically convert them…

1 Like

Bonus! As you can imagine, I’m using the correct units (:wink: ) - and that’s why having “wrong ones” in the mix is just as bad. So I refactored everything and now I only have one item in the items file - and the good thing is: depending on your configured locale - it even comes in the right unit, regardless of Input.
Why? Because what I learned, Unit of Measurement is as cool as it gets:

  1. you define in your locale, what unit you like
  2. if the item is updated (either via binding or REST-API), you can add the unit in which you have in your source
  3. openHAB will automagically store the value and give you the right unit back, as you requested.

So in my case: my source is imperial and my locale is metric. If the source updates the items and while doing this is telling openHAB the unit - openHAB calculates it accordingly.

So - my PHP now looks like this (I know, it’s a bit dirty, but works):

<?
$weatherprefix = "WeatherStation_"; // if you have a prefix in your OH2 items configuration
// resends all GET-Values directly to OH2 API
foreach ($_GET 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 (substr($key, -3)) {
		case "mpf":
			// unit is in Fahrenheit (remove "f")
			sendOH2Command($weatherprefix.str_replace("mpf", "mp", $key), f2c($value));
			break;
		case "ptf":
			// unit is in Fahrenheit also (remove "f")
			sendOH2Command($weatherprefix.str_replace("ptf", "pt", $key), f2c($value));
			break;
		case "llf":
			// unit is in Fahrenheit also (remove "f")
			sendOH2Command($weatherprefix.str_replace("llf", "ll", $key), f2c($value));
			break;
		case "min":
			// unit is in inHg (remove "min")
			sendOH2Command($weatherprefix.str_replace("min", "", $key), inHG2hPa($value));
			break;
		case "nin":
			// unit is in inch (remove "in")
			sendOH2Command($weatherprefix.str_replace("nin", "n", $key), in2cm($value));
			break;
		case "mph":
			// 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
			sendOH2Command($weatherprefix.$key, $value);
	}	
}

function sendOH2Command($item, $data) {
  $url = "http://192.168.xxx.xxx:8080/rest/items/" . $item;

  $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 f2c($given_value) {
	$celsius = round(5/9*($given_value-32),2);
	settype($celsius, "string");
	return $celsius;
}

function inHG2hPa($given_value) {
	$hpa = round(floatval($given_value) * 33.862,2);
	settype($hpa, "string");
	return $hpa;
}

function in2cm($given_value){
    $cm = round(floatval($given_value) * 2.54,2);
	settype($cm, "string");
	return $cm;
}

function mph2kmh($given_value) {
	$kmh = round(floatval($given_value) * 1.6,2);
	settype($kmh, "string");
	return $kmh;
}

function str2UTC($given_value) {
	$UTC = str_replace(" ", "T", $given_value);
	return $UTC;
}

?>

my items look like this:

String 					Weatherstation_JSON 			"Wetterstation JSON"
Group					Wetter							"Wetter Überblick"								(All)

// Allgemeine Infos
String 					Weatherstation_ID				"ID"
String 					Weatherstation_PASSWORD			"PWD"
DateTime				Weatherstation_dateutc			"Uhrzeit"							<temperature>	(gWeather, Wetter)	
String 					Weatherstation_softwaretype		"Software"							<temperature>	(gWeather, Wetter)	
String 					Weatherstation_action			"Wetteraktion"						<temperature>	(gWeather, Wetter)	
String 					Weatherstation_realtime			"Realtime"							<temperature>	(gWeather, Wetter)	
String 					Weatherstation_rtfreq			"Updatefrequenz"					<temperature>	(gWeather, Wetter)

// Temperaturen
Number:Temperature 		Weatherstation_indoortemp		"Innen Temperature [%.1f %unit%]"	<temperature>	(gWeatherTemp, Wetter)	
Number:Temperature 		Weatherstation_temp				"Aussen Temperature [%.1f %unit%]"	<temperature>	(gWeatherTemp, Wetter)	
Number:Temperature 		Weatherstation_dewpt				"Taupunkt [%.1f %unit%]"			<temperature>	(gWeatherTemp, Wetter)	
Number:Temperature 		Weatherstation_windchill			"Windchill [%.1f %unit%]"			<temperature>	(gWeatherTemp, Wetter)

// Luftdruck
Number:Pressure 		Weatherstation_baro				"Luftdruck min [%.1f %unit%]"		<temperature>	(gWeatherPressure, Wetter)	
Number:Pressure 		Weatherstation_absbaro			"Abs. Luftdruck min [%.1f %unit%]"	<temperature>	(gWeatherPressure, Wetter)	

// Niederschlag
Number:Length 			Weatherstation_rain				"Niederschlag [%.1f mm]"		<temperature>	(gWeatherHeight, Wetter)	
Number:Length 			Weatherstation_dailyrain			"Niederschlag/Tag [%.1f mm]"	<temperature>	(gWeatherHeight, Wetter)	
Number:Length 			Weatherstation_weeklyrain		"Niederschlag/Woche %.1f mm]"	<temperature>	(gWeatherHeight, Wetter)	
Number:Length 			Weatherstation_monthlyrain		"Niederschlag/Monata [%.1f mm]" <temperature>	(gWeatherHeight, Wetter)	

// Wind
String 					Weatherstation_winddir			"Windrichtung"						<temperature>	(gWeather, Wetter)	
Number:Speed 			Weatherstation_windspeed			"Windgeschwindigkeit [%.1f %unit%]" 	<temperature>	(gWeatherSpeed, Wetter)	
Number:Speed 			Weatherstation_windgust			"Windböen [%.1f %unit%]"				<temperature>	(gWeatherSpeed, Wetter)	

// Feuchtigkeit
Number 					Weatherstation_humidity			"Außen Feuchtigkeit [%.1f %%]"	<temperature>	(gWeather, Wetter)	
Number 					Weatherstation_indoorhumidity	"Innen Feuchtigkeit [%.1f %%]"	<temperature>	(gWeather, Wetter)	

// Sonneneinstrahlung
Number 					Weatherstation_solarradiation	"Solareintrag [%.1f]"			<temperature>	(gWeather, Wetter)	
Number 					Weatherstation_UV				"UV-Index [%.1f]"				<temperature>	(gWeather, Wetter)	


1 Like

Hello binderth!

We have the same weather station and we will get the data to our server.
Why do you need a openHAB API?
We can use only php on our server and i want to save data from weather station to a simple text file.
Do you think thats possible?
Many Thanks!
Andy

Hi Andy,

just adjust the PHP-script above, so that it writes the values to a text file.
I use OH2 for this, because

  1. it’s an openHAB community forum here! :wink:
  2. I’d like to have my shutters moving up in case of severe wind (rain or even frost isn’t an issue with my type of shutters, but you could use that information also)[1]
  3. I persist the weather information via openHAB, so I can have cute little graphs and historic comparisons over time.

[1] as the station also gives updates on UV and sunlight I could imagine giving out some warnings on my smart display to not forget sunscreen or something like that…

Hi Thomas,
Thanks for your reply - i hope i can change to write into textfile - i’ll give them a try.

Many Thanks!!!

PS: you’re German? because of the text in the items list (i’m from Austria)

Andy

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!