Send local weather information via binding (http?) to openweahtermap

Tags: #<Tag:0x00007f2fbb67d300>

So, first Hello to all.

i am working with a Raspberry pi 3b+ and the razberry modul. And for some weeks now, i have a little weatherstation in my garden based on the tinkerforge system. Up to here, everything’s fine and no problems.
Now the neighbours have of course seen that such a white box is in the garden and asked if they can get the data.
Since I don’t want to open access to the WLAN, my idea was to send the data to openweathermap (as a new station) and simply give them the link to station. On the Website of openweathermap i can find the informatoin how to add data, but did not understand (because of my rather non-existent programming Knowledge) how to do that with openhab.
Add neew Station in openweathermap

As an alternative, if easier: i have some webspace (hosted) where i can to “something”.

Please notice, i am a not really talented beginner.

And for informaion, for the beginng i want to give Information about temperature, humidity and pressure, in a second step (Need to buy the sensors) for windspeed, direction and rain, maybe for UV-light and ozone.

Many thanks in advance for your help. :grinning:

IMHO sending own data to openweathermap is not part of the openweathermap binding.

This is currently outside the scope of openHAB.

But the OpenWeathermap API looks to be pretty simple, You would need to use the sendHttp*Request Actions (if possible) to issue the POST and PUT commands necessary to update the sensor readings from your weather station. If you need to do more than is supported by the Actions, you may need to use executeCommandLine and use the curl command. It’s going to take some research and trying stuff out to make it work but it should be pretty achievable.

I do agree with Jürgen, this is out of scope for the openweathermap binding.

Thanks for your answer, but one Question. (My english is not the best)
Did i have under something wrong here ?
Openweathermap - Three simple steps to connect your station

I don’t understand the question. The link is to how to construct the HTTP PUT request to modify information about your weather station. You put that JSON in the body of your request and it will return the indicated JSON as a response.

So to come back to this topic, i try to tinker a little bit and if i send a post request (with postman) i get a answer and i can look to the data via get. But when i try with OH, i am not able to send my information,
had somebody a idea whats going wrong ?

rule “Daten an OWM schicken”

when
Time cron “0 0/30 * * * ?” // every 30 minutes
then
var epoch = now().getMillis()
var Number temperatur = Temperatur.state as DecimalType
var Number luftfeuchte = Luftfeuchte.state as DecimalType
var Number luftdruck =Luftdruck.state as DecimalType
val String URL = “http://api.openweathermap.org/data/3.0/measurements?APPID=APPID”
var String contenttype = “application/json”
var String jsondata = ‘{“station_id”: “STATIONID”,“dt”: ‘+epoch+’,“temperature”: ‘+temperatur+’,“pressure”: ‘+luftdruck+’,“humidity”: ‘+luftfeuchte+’}’
sendHttpPostRequest(URL, contenttype, jsondata)

end

Try

var results = sendHttpPostRequest(URL, contenttype, jsondata)
logInfo ("test", "results: " + results.toString)

To make it short.
Did not work.

Make it long. What did it say? That was a diagnostic move, an attempt to find out what is wrong. Not a fix.

What is in openhab.log ?

That is in the log file.

results: {“code”:400001,“message”:“syntax error: offset=84, error=invalid character ‘Â’ after object key:value pair”}

Okay, openweathermap has rejected your message. Mention of key:value pair suggests they don’t like your JSON, try logging that out to review what you have built.

logInfo ("test", "JSON: " + jsondata)

I would guess that you need to convert your Numbers to strings when adding them to the jsondata string.

That is the result:

JSON: {“station_id”: “STATION_ID”,“dt”: 1567013580030,“temperature”: 28.16 °C,“pressure”: 1014.213 mbar,“humidity”: 61.02 %}

When i try the var Number… as Decimal Type:
Error during the execution of rule ‘Daten schicken’: Could not cast 28.15 °C to org.eclipse.smarthome.core.library.types.DecimalType; line 12, column 29, length 49

And when i try “state as String” the same error with “could not cast…to String”

I’m going to guess that the web service doesn’t like the “°C”. It will have a similar problem with the “mbar” and “%”.

Your Numbers Items are using units of measure. For example

Number:Temperature Temperatur

You need to remove the units from all of these Item’s states, and you need to convert the pressure to hPa instead of mbar.

val temperatur = (Temperatur.state as QuantityType<Number>).floatValue()

So there is no more error, the log said that the data has been send but i did not reach openweathermap.
Example:
JSON: {“station_id”: “ID”,“dt”: 1567104060124,“temperature”: 23.15,“pressure”: 1020.493,“humidity”: 80.76}

And to be honest. I want the expand the system in the next days/weeks/months with some sensors that openweathermap can’t handle and so i have to look for something else anyway. So i am waiting for the TF binding integration from wind and rain (As far as I can know, it’s in work) and i want to implent particulate matter sensor (That is the measurement owm cant “read”). So i think i had to look to a differnt solution to share my data with the neigbours. So i startet a new post.
Link to additional post

BUT, if someone has a idea what possible go wrong, i can test it with my second pi and publish if it work, or not.

What is the response from openweathermap now?

Hi Stefan,

Just stumbled over your post. Maybe I have a solution for you. I found an old branch in my private repository - nearly have a year old - where I started to implement the support for Station API in the OpenWeatherMap binding. Some changes in the build process stopped my work and I never picked it up again. If I will find some time I can try to prepare a beta version for you for testing purposes. Wdyt?

IIRC I had some design issue where I was not sure how to move on. Like to discuss them once I figured them out again.

Good Idea!