Page 1 of 6

Weather Underground Upload script

Posted: Sunday 03 November 2013 12:58
by gizmocuz
Okey, here is my first lua script... this script will upload your weather data to weather underground.
For this you need version #1137 at least duo some new lua variables.

Name this script something like "script_time_wu.lua" , then the script will be called every minute.
But i think we need to let it call every 5 minutes!... changes welcome :ugeek:

You need to change the:
- StationID
- Password
- Weather devices

If you do not own a particular weather device, leave the string blank.

Any feedback/improvements welcome ;)

Code: Select all

-- Weatherunderground PWS upload script
-- (C)2013 GizMoCuz

Outside_Temp_Hum = 'MyTempHumBaro'
Barometer = 'MyTempHumBaro'
RainMeter = 'MyRain'
WindMeter = 'MyWind'
UVMeter = 'MyUV'

--WU Settings
baseurl = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?"
ID = "yourstationid"
PASSWORD = "yourpassword"

local function CelciusToFarenheit(C)
	return (C * (9/5)) + 32
end 

local function hPatoInches(hpa)
	return hpa * 0.0295301
end

local function mmtoInches(mm)
	return mm * 0.039370
end

utc_dtime = os.date("!%m-%d-%y %H:%M:%S",os.time())

month = string.sub(utc_dtime, 1, 2)
day = string.sub(utc_dtime, 4, 5)
year = "20" .. string.sub(utc_dtime, 7, 8)
hour = string.sub(utc_dtime, 10, 11)
minutes = string.sub(utc_dtime, 13, 14)
seconds = string.sub(utc_dtime, 16, 17) 

timestring = year .. "-" .. month .. "-" .. day .. "+" .. hour .. "%3A" .. minutes .. "%3A" .. seconds

SoftwareType="Domoticz"

WU_URL= baseurl .. "ID=" .. ID .. "&PASSWORD=" .. PASSWORD .. "&dateutc=" .. timestring
--&winddir=230
--&windspeedmph=12
--&windgustmph=12

if Outside_Temp_Hum ~= '' then
	WU_URL = WU_URL .. "&tempf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
	WU_URL = WU_URL .. "&humidity=" .. otherdevices_humidity[Outside_Temp_Hum]
	WU_URL = WU_URL .. "&dewptf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_dewpoint[Outside_Temp_Hum]))
end

if Barometer ~= '' then
	WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_barometer[Barometer]))
end

if RainMeter ~= '' then
	WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
	WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end

if WindMeter ~= '' then
	WU_URL = WU_URL .. "&winddir=" .. string.format("%.0f", otherdevices_winddir[WindMeter])
	WU_URL = WU_URL .. "&windspeedmph=" .. string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
	WU_URL = WU_URL .. "&windgustmph=" .. string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end

if UVMeter ~= '' then
	WU_URL = WU_URL .. "&UV=" .. string.format("%.1f", mmtoInches(otherdevices_uv[UVMeter]))
end

--&weather=
--&clouds=

WU_URL = WU_URL .. "&softwaretype=" .. SoftwareType .. "&action=updateraw"

--print (WU_URL)

commandArray = {}

--remove the line below to actualy upload it
--commandArray['OpenURL']=WU_URL

return commandArray
You can remove the marks infront of the print function to display the url (and test)
if all works well, remark that print line, and remove the marks for the commandArray/OpenURL command

With kind regards,
Rob

Re: Weather Underground Upload script

Posted: Wednesday 06 November 2013 14:29
by Shunt
Thanks for the script. Good work!

I use this to run every 5 minutes:

Code: Select all

-- Current date as date.year, date.month, date.day, date.hour, date.min, date.sec
date = os.date("*t")
if (date.min % 5 == 0) then
  --script
end
Unfortunately the lua execution time seems to drag about a second per hour, which means you'll end up with all the lua scripts running at (for example) 14:59:59, and the next execution at 15:01:00, which means that a script set to run at 15:00 will fail every few days.

I've logged this on two systems using:

Code: Select all

date = os.date("*t")
commandArray = {}
print ("Heartbeat: " .. date.hour .. ":" .. date.min .. ":" .. date.sec)
return commandArray
Which returns (edited, to keep it short):

Code: Select all

LUA: Heartbeat: 11:00:07
LUA: Heartbeat: 11:01:07
...
LUA: Heartbeat: 11:11:08
LUA: Heartbeat: 11:12:08
...
LUA: Heartbeat: 12:13:09
LUA: Heartbeat: 12:14:09
...
LUA: Heartbeat: 13:20:10
LUA: Heartbeat: 13:21:10
...
LUA: Heartbeat: 14:21:11
LUA: Heartbeat: 14:22:11

Re: Weather Underground Upload script

Posted: Monday 21 July 2014 22:47
by epierre
leaving a device blank does not seem to be enough, I have a Temp+Hum AND a baro (separated) and it seems to be some trouble I don't know where...
Mon Jul 21 22:48:41 2014 Error: /home/pi/domoticz/scripts/lua/script_time_wu.lua:20: attempt to perform arithmetic on local 'hpa' (a nil value)
because the individual barometer remorts bar and not hpa !
198 MySensors1 82197 1 Mysensors Baro General Pressure 1013.0 Bar
what should I use instead of
otherdevices_barometer[Barometer]
? :?:
local a=otherdevices[Barometer]
print(a)
brings nothing... :!:

Re: Weather Underground Upload script

Posted: Wednesday 23 July 2014 21:19
by epierre
Ok found, for pressure you need to go through svalues... so here is the code to add to send a Pressure device as a barometer:

Code: Select all

Pressure = 'Mysensors Baro'

if Pressure ~= '' then
   WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_svalues[Pressure]))
end

Re: Weather Underground Upload script

Posted: Thursday 04 September 2014 21:04
by epierre
Why do 20.1 in RFX become 20.10000038147 in the lua script and have the script fail ? ? ?

WUnderground Upload script of Nexus-data received via RFXCom

Posted: Wednesday 07 January 2015 23:17
by Toulon7559
In my configuration a Nexus-PWS collects meteo-information and transmits it via USB-interface to a server.
That could be Domoticz@Raspberry via TE923-USB-interface, but beside Wunderground I need to support a few more functions only available in Windows-software, and therefore a Windows-PC is the primary server. Unfortunately that Windows-server sometimes 'freezes' or crashes.
Domoticz@Raspberry through the RFXCom as alternative routing can directly receive the wireless information from the most important Nexus-sensors for wind, temperature and humidity (not for pressure).
For a foolproof, continuous upload the idea is that the Windows-server is the primary uploader per 10 minutes, while Domoticz with a lua-script is uploading at much lower rate as gapfiller, in that way assuring upload when the Windows-server fails. The script provided by gizmocuz (expanded with the '5-minute'-hint by Shunt) is a good starting point to make Domoticz a perodic upload server towards Wunderground.

From testing two aspects certainly to tackle for improvement.
1. If upload from the Windows-server is off, the upload by Domoticz is OK [but it obviously misses barometer-info], and reversely.
If both uploaders run in parallel, then it is not clear which info will be taken by Wunderground, certainly the Windows-server does not have priority, but the timing of registration is visibly affected.
A pragmatic solution seems to put in the lua-script a mechanism by which Domoticz checks on downloaded WU-info whether Wunderground has a recent barometer-value, and when that lacks for some time, only then starts uploading. Somebody an idea how to realise such mechanism?
2. At the Domoticz-side in the log I see every minute an error-report like
2015-01-07 23:03:00 Error: .../pi/domoticz/scripts/lua/script_time_wu_nexus_upload.lua:51: attempt to concatenate global 'WU_URL' (a nil value)
;-) Does (apparently) not hurt, but not nice. Have the feeling that this is result of a once/minute-check with negative result. How to get rid of that error-report?

<The adapted script is below: the text within&including [color][/color]-markings has to be adapted for your own configuration>
If you do not use the 'wireless info' from the Nexus-sensor, but instead directly connect the NEXUS-console to the Raspberry by USB as a TE923-Hardware, then you can also fill-in and activate the lines relating to Barometer, including the local function hPatoInches(hpa)

Code: Select all

-- Weatherunderground PWS upload script
-- (C)2013 GizMoCuz, adapted by Toulon7559 for periodic upload of nexus-info received wireless via RFXCom

-- Identification of Nexus-sensors as appearing in Domoticz-display for Weather
Outside_Temp_Hum = '[color=#800000]TFA_Temp_RV[/color]'
-- Barometer = ' '
RainMeter = '[color=#800000]TFA_Nexus_Neerslag[/color]'
WindMeter = [color=#800000]'TFA_Nexus_Wind'[/color]
-- UVMeter = ' '

-- WU Settings
baseurl = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?"
ID = "[color=#800000]WU-identiteit[/color]"
PASSWORD = "[color=#800000]wachtwoord[/color]"
Interval = [color=#800000]15[/color]

local function CelciusToFarenheit(C)
   return (C * (9/5)) + 32
end

-- local function hPatoInches(hpa)
--   return hpa * 0.0295301
-- end

local function mmtoInches(mm)
   return mm * 0.039370
end

utc_dtime = os.date("!%m-%d-%y %H:%M:%S",os.time())

month = string.sub(utc_dtime, 1, 2)
day = string.sub(utc_dtime, 4, 5)
year = "20" .. string.sub(utc_dtime, 7, 8)
hour = string.sub(utc_dtime, 10, 11)
minutes = string.sub(utc_dtime, 13, 14)
seconds = string.sub(utc_dtime, 16, 17)

timestring = year .. "-" .. month .. "-" .. day .. "+" .. hour .. "%3A" .. minutes .. "%3A" .. seconds

SoftwareType="Domoticz"

-- Current date from os as date.year, date.month, date.day, date.hour, date.min, date.sec
-- Check time in minutes against Interval to start script
date = os.date("*t")
if (date.min % Interval == 0) then
WU_URL= baseurl .. "ID=" .. ID .. "&PASSWORD=" .. PASSWORD .. "&dateutc=" .. timestring
--&winddir=230
--&windspeedmph=12
--&windgustmph=12
end

if Outside_Temp_Hum ~= '' then
   WU_URL = WU_URL .. "&tempf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
   WU_URL = WU_URL .. "&humidity=" .. otherdevices_humidity[Outside_Temp_Hum]
   WU_URL = WU_URL .. "&dewptf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_dewpoint[Outside_Temp_Hum]))
end

-- if Barometer ~= '' then
--    WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_barometer[Barometer]))
-- end

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end

if WindMeter ~= '' then
   WU_URL = WU_URL .. "&winddir=" .. string.format("%.0f", otherdevices_winddir[WindMeter])
   WU_URL = WU_URL .. "&windspeedmph=" .. string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
   WU_URL = WU_URL .. "&windgustmph=" .. string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end

-- if UVMeter ~= '' then
--    WU_URL = WU_URL .. "&UV=" .. string.format("%.1f", (otherdevices_uv[UVMeter]))
-- end

--&weather=
--&clouds=

WU_URL = WU_URL .. "&softwaretype=" .. SoftwareType .. "&action=updateraw"

print (WU_URL)

commandArray = {}

--remove -- before the line below to actualy upload
--commandArray['OpenURL']=WU_URL

return commandArray

Re: Weather Underground Upload script

Posted: Monday 13 April 2015 18:04
by Toulon7559
Presently running upload of meteo-data from Domoticz parallel to upload from WsWin.
Both Domoticz and WsWin take information from my meteo-set TFA_Nexus:
- WsWin gets the complete info-set via the USB-interface from the console
- Domoticz uses the wireless information from the sensors, which lacks pressure-info (because produced in the console).
WsWin-upload is at an interval of 10 minutes, Domoticz-upload is planned as backup at an interval of 55 minutes.
Wunderground merges both streams to one set of tables and graphs.
Not all ;-) 'sunshine' for this merging, because some side-effects in the Wunderground-display:
- in Daily Mode sometimes no data in the Summary-fields, because that function requires a consistent stream for some time
- for the Day-table and Day-graph all received data is applied, with the lack of pressure-info visible as -- indications in the table and as periodic 'holes' in the pressure-graph.
That latter effect for obvious reason: no data = no display .......

Goal (and benefit) of this setup:
the upload to Wunderground continues (with some limitations) even if my main server stops => improved continuity of information by redundancy
Schermafdruk 2015-04-13 18.01.05.png
Schermafdruk 2015-04-13 18.01.05.png (206.52 KiB) Viewed 18918 times

Re: Weather Underground Upload script

Posted: Sunday 03 May 2015 15:47
by arnaudth
Hi everybody,

I was trying this script but I've got error when function mmtoInches(mm) occurs.
It seems otherdevices_rain and otherdevices_rain_lasthour don't return any value or I'm using them wrong.

I've made this script :
commandArray = {}
RainMeter = 'Pluviomètre'
print (RainMeter)
print (otherdevices_rain[RainMeter])
print (otherdevices_rain_lasthour[RainMeter])
return commandArray

In log I only got :
.....
2015-05-03 15:38:00.329 LUA: Pluviomètre
.....

But this script :
commandArray = {}
RainMeter = 'Pluviomètre'
print (RainMeter)
sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[RainMeter]:match("([^;]+);([^;]+)")
sRainmeterCurrent = tonumber(sRainmeterCurrent)/100
sRainmeterTotal = tonumber(sRainmeterTotal)
print (otherdevices_rain[RainMeter])
print (otherdevices_rain_lasthour[RainMeter])
print ("sRainmeterCurrent is ".. sRainmeterCurrent .." mm/h")
print ("sRainmeterTotal is ".. sRainmeterTotal .." mm")
return commandArray

In log I got :
.....
2015-05-03 15:40:00.815 LUA: Pluviomètre
2015-05-03 15:40:00.815 LUA: sRainmeterCurrent is 0 mm/h
2015-05-03 15:40:00.816 LUA: sRainmeterTotal is 31.4 mm
.....

Can anyone help me ?
I'm using Domoticz 2.2284 on RaspberryPi
Thanx

Re: Weather Underground Upload script

Posted: Monday 15 June 2015 18:32
by arnaudth
Just install V2.2563 and now it works.

Re: Weather Underground Upload script

Posted: Wednesday 01 July 2015 13:08
by theezeefje
gizmocuz,

Can you add support for the Soil Moisture and Soil Temp ?
I bought myself a Opus XT300 Wireless Moisture sensor, would like to send this data to WU.

Re: Weather Underground Upload script

Posted: Wednesday 01 July 2015 20:53
by arnaudth
Hi,
You can modify the script to fit your needs.
Here is some help http://wiki.wunderground.com/index.php/ ... d_Protocol.

Re: Weather Underground Upload script

Posted: Saturday 04 July 2015 19:51
by Sjonnie
I'am successfully uploading data to WU (Hilversum) except for my barometer which is a BMP085 on I2c. This works fine in Domoticz but I can't seem to get the script working. I keep getting this error:
Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_wu.lua:53: attempt to index global 'otherdevices_barometer' (a nil value)

also the attempt with setting it as Svalue as Epierre stated doesn't seem to work.
The Barometer returns in hPa according to Domoticz.
Has anybody got an idea what i' am doing wrong?
This is the script I use:

Code: Select all

-- Weatherunderground PWS upload script
-- (C)2013 GizMoCuz

Outside_Temp_Hum = 'Outside Temp Hum'
Barometer = 'Baro Temp'
RainMeter = 'Rain Meter'
WindMeter = 'Wind Meter'
UVMeter = ''
Pressure = ''

--WU Settings
baseurl = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?"
ID = ""
PASSWORD = ""

local function CelciusToFarenheit(C)
   return (C * (9/5)) + 32
end 

local function hPatoInches(hpa)
   return hPa * 0.0295301
end

local function mmtoInches(mm)
   return mm * 0.039370
end

utc_dtime = os.date("!%m-%d-%y %H:%M:%S",os.time())

month = string.sub(utc_dtime, 1, 2)
day = string.sub(utc_dtime, 4, 5)
year = "20" .. string.sub(utc_dtime, 7, 8)
hour = string.sub(utc_dtime, 10, 11)
minutes = string.sub(utc_dtime, 13, 14)
seconds = string.sub(utc_dtime, 16, 17) 

timestring = year .. "-" .. month .. "-" .. day .. "+" .. hour .. "%3A" .. minutes .. "%3A" .. seconds

SoftwareType="Domoticz"

WU_URL= baseurl .. "ID=" .. ID .. "&PASSWORD=" .. PASSWORD .. "&dateutc=" .. timestring
--&winddir=230
--&windspeedmph=12
--&windgustmph=12

if Outside_Temp_Hum ~= '' then
   WU_URL = WU_URL .. "&tempf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
   WU_URL = WU_URL .. "&humidity=" .. otherdevices_humidity[Outside_Temp_Hum]
   WU_URL = WU_URL .. "&dewptf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_dewpoint[Outside_Temp_Hum]))
end

if Barometer ~= '' then
   WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_barometer[Barometer]))
end

if Pressure ~= '' then
   WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_svalues[Pressure]))
end

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end

if WindMeter ~= '' then
   WU_URL = WU_URL .. "&winddir=" .. string.format("%.0f", otherdevices_winddir[WindMeter])
   WU_URL = WU_URL .. "&windspeedmph=" .. string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
   WU_URL = WU_URL .. "&windgustmph=" .. string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end

if UVMeter ~= '' then
   WU_URL = WU_URL .. "&UV=" .. string.format("%.1f", mmtoInches(otherdevices_uv[UVMeter]))
end

--&weather=
--&clouds=

WU_URL = WU_URL .. "&softwaretype=" .. SoftwareType .. "&action=updateraw"

--print (WU_URL)

commandArray = {}

--remove the line below to actualy upload it
commandArray['OpenURL']=WU_URL

Re: Weather Underground Upload script

Posted: Saturday 04 July 2015 22:19
by arnaudth
Hi

Code: Select all

local function hPatoInches(hpa)
   return hPa * 0.0295301
end
should be

Code: Select all

local function hPatoInches(hPa)
   return hPa * 0.0295301
end
hpa -> hPa
I don't see any other error. Try it and tell me if it works.

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 13:26
by Toulon7559
@Sjonnie

Why are you using the lines with 'Pressure'?
In my opinion the srciptlines 9, 53, 54 and 55 (if I correctly counted) are a functional duplicate of the lines with 'Barometer', and because line 9 is an 'empty' declaration (because no name given in ' ') that may lead to an errorreport on line 53.
Suggest that you deactivate those 4 lines by putting -- in front of the text of each line, and then see whether you still have that errorreport.

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 14:15
by Sjonnie
Hi Toulon
I tried using the svalue option because of a suggestion made by another Domoticz user to to experiment. I will try your suggestion tonight when i get home from work and let you know. I think this could well be the solution.
Thanks a lot!
I'll let you know..

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 19:11
by Toulon7559
@Sjonnie

For quick check that the 'Barometer'-section generates correct output, you could insert a temporary, extra line just after that section:
print ('WU_URL=' .. WU_URL)
When you testrun the script including that extra line, then in the Domoticz-log you can see the WU_URL originating from that section

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 21:17
by Sjonnie
I'am still puzzled; still got the alarm and I was so convinced your suggestion would help.

2015-07-06 21:07:00.374 Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_wu.lua:53: attempt to index global 'otherdevices_barometer' (a nil value)

I' am still doing something wrong with the print statement because i can't see anything being echoed back in the log of Domoticz.
Once again my lua script as it currently is in the state it should print and not actually upload:

Code: Select all

-- Weatherunderground PWS upload script
-- (C)2013 GizMoCuz

Outside_Temp_Hum = 'Outside Temp Hum'
Barometer = 'Baro Temp'
RainMeter = 'Rain Meter'
WindMeter = 'Wind Meter'
UVMeter = ''


--WU Settings
baseurl = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?"
ID = ""
PASSWORD = ""

local function CelciusToFarenheit(C)
   return (C * (9/5)) + 32
end 

local function hPatoInches(hPa)
   return hPa * 0.0295301
end

local function mmtoInches(mm)
   return mm * 0.039370
end

utc_dtime = os.date("!%m-%d-%y %H:%M:%S",os.time())

month = string.sub(utc_dtime, 1, 2)
day = string.sub(utc_dtime, 4, 5)
year = "20" .. string.sub(utc_dtime, 7, 8)
hour = string.sub(utc_dtime, 10, 11)
minutes = string.sub(utc_dtime, 13, 14)
seconds = string.sub(utc_dtime, 16, 17) 

timestring = year .. "-" .. month .. "-" .. day .. "+" .. hour .. "%3A" .. minutes .. "%3A" .. seconds

SoftwareType="Domoticz"

WU_URL= baseurl .. "ID=" .. ID .. "&PASSWORD=" .. PASSWORD .. "&dateutc=" .. timestring
--&winddir=230
--&windspeedmph=12
--&windgustmph=12

if Outside_Temp_Hum ~= '' then
   WU_URL = WU_URL .. "&tempf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
   WU_URL = WU_URL .. "&humidity=" .. otherdevices_humidity[Outside_Temp_Hum]
   WU_URL = WU_URL .. "&dewptf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_dewpoint[Outside_Temp_Hum]))
end

if Barometer ~= '' then
   WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(otherdevices_barometer[Barometer]))
end

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end

if WindMeter ~= '' then
   WU_URL = WU_URL .. "&winddir=" .. string.format("%.0f", otherdevices_winddir[WindMeter])
   WU_URL = WU_URL .. "&windspeedmph=" .. string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
   WU_URL = WU_URL .. "&windgustmph=" .. string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end

if UVMeter ~= '' then
   WU_URL = WU_URL .. "&UV=" .. string.format("%.1f", mmtoInches(otherdevices_uv[UVMeter]))
end

--&weather=
--&clouds=

WU_URL = WU_URL .. "&softwaretype=" .. SoftwareType .. "&action=updateraw"

print (WU_URL)

commandArray = {}

--remove the line below to actualy upload it
--commandArray['OpenURL']=WU_URL

return commandArray
This is the Barometer device itself:

I appreciate your help!

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 23:01
by Toulon7559
A BMP180 is waiting to be connected to my Raspberry.
Later this week will try to accelerate that job, to join you in experimenting with this script.
;-) Better than just reading the listing.

PS Nothing wrong with the print statement, but if the previous lines have an error, then that print statement will not be executed.
In other words: we have to find the cause for the error in line 53 before we will see a print.

Re: Weather Underground Upload script

Posted: Monday 06 July 2015 23:38
by Sjonnie
That would be great!
In the meantime here the echoed string by Domoticz log:

Code: Select all

LUA: http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=&PASSWORD=&dateutc=2015-07-06+21%3A34%3A00&tempf=66.7&humidity=61&dewptf=52.9&dailyrainin=0.00&rainin=0.00&winddir=90&windspeedmph=0&windgustmph=0&softwaretype=Domoticz&action=updateraw
Still i don't know what to do with it ;-)

Best Regards

Re: Weather Underground Upload script [incl. BMP180]

Posted: Tuesday 14 July 2015 17:07
by Toulon7559
Some delay due to higher priorities (and ;-) too much sunshine to work inside), but today's rainy day gave time to experiment & test with BMP180 and lua-script.

Below is an adapted version of the earlier script.
This new version includes the read-out of data from BMP180 and its inclusion in the upload message to Wunderground.
The line-numbers give some guidance for reading and for error-trapping.
The section starting at line 53 extracts the data from the svalues related to BMP180.
An application of BMP180-temperature is not foreseen, and the 'print-lines' are only interesting for test-view in the log: therefore the applicable lines have -- in front.
In line 67 you see the URL compiled for upload of BMP180 barometric pressure.
Tested & implemented, in my case as 'backup/gapfiller' for the normal upload by the meteo-software WsWin, with rate as defined by the interval-parameter in line 15.

This milestone achieved, but the result again causes some headscratching ( ;-) to keep me busy):
- a difference between the pressure info in the uploadstream from WsWin and in the uploadstream by this script can be expected due to difference in sensor, in type of measurement&processing, in timing etc. The difference seems a more or less constant bias. Because both uploadstreams are periodic with different fixed intervals, the difference in value shows as periodic zig-zags in the graph between the WsWin-value and the BMP180-value.
- but in the Wunderground graph/table at the points that the pressure from BMP180 is applied I also see significantly lower accumulated rain related to WsWin-info.
That makes no sense, because both uploads use initial data from the same Nexus-rainmeter.
I have the suspicion that the bookkeeping of Domoticz for accumulated rain is at least different from the 'real' meteo-software WsWin, possibly due to the different interval for read-out:
(in my opinion) therefore the upload from Domoticz is not a real substitute for info directly coming from a PWS, but at best a backup/gapfiller.

Interested to hear your opinion & experiences, and improvements.

Code: Select all

-- Weatherunderground PWS upload script
-- (C)2013 GizMoCuz, adapted by Toulon7559 for periodic upload of Nexus-info received via RFXCom, supplemented by pressure-info from a BMP180 sensor

-- Line 05, Defintion of inputs
Outside_Temp_Hum = 'TFA_Nexus_Temp_RV'
Barometer = 'BMP180_Temp_Baro'
RainMeter = 'TFA_Nexus_Neerslag'
WindMeter = 'TFA_Nexus_Wind'
-- UVMeter = ' '

-- Line 12, WU Settings
baseurl = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?"
ID = "Your_WU_ID"
PASSWORD = "Your_WU_PW"
Interval = 55

-- Line 18, Local functions
local function CelciusToFarenheit(C)
   return (C * (9/5)) + 32
end

local function hPatoInches(hpa)
   return hpa * 0.0295301
end

local function mmtoInches(mm)
   return mm * 0.039370
end

-- Line 31, Extraction of required calendar info
utc_dtime = os.date("!%m-%d-%y %H:%M:%S",os.time())
month = string.sub(utc_dtime, 1, 2)
day = string.sub(utc_dtime, 4, 5)
year = "20" .. string.sub(utc_dtime, 7, 8)
hour = string.sub(utc_dtime, 10, 11)
minutes = string.sub(utc_dtime, 13, 14)
seconds = string.sub(utc_dtime, 16, 17)

timestring = year .. "-" .. month .. "-" .. day .. "+" .. hour .. "%3A" .. minutes .. "%3A" .. seconds

SoftwareType="Domoticz"

-- Line 44, Current date as date.year, date.month, date.day, date.hour, date.min, date.sec
date = os.date("*t")
if (date.min % Interval == 0) then
WU_URL= baseurl .. "ID=" .. ID .. "&PASSWORD=" .. PASSWORD .. "&dateutc=" .. timestring
--&winddir=230
--&windspeedmph=12
--&windgustmph=12
end

-- Line 53, Extraction of data from BMP180
sBMP180T, sBMP180B = otherdevices_svalues[Barometer]:match("([^;]+);([^;]+)")
-- sBMP180T = tonumber(sBMP180T);
-- print ('BMP180_temp = '.. sBMP180T) 
sBMP180B = tonumber(sBMP180B);
-- print ('BMP180_druk = '.. sBMP180B)

if Outside_Temp_Hum ~= '' then
   WU_URL = WU_URL .. "&tempf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
   WU_URL = WU_URL .. "&humidity=" .. otherdevices_humidity[Outside_Temp_Hum]
   WU_URL = WU_URL .. "&dewptf=" .. string.format("%3.1f", CelciusToFarenheit(otherdevices_dewpoint[Outside_Temp_Hum]))
end

if Barometer ~= '' then
   WU_URL = WU_URL .. "&baromin=" .. string.format("%2.2f", hPatoInches(sBMP180B))
end

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end

if WindMeter ~= '' then
   WU_URL = WU_URL .. "&winddir=" .. string.format("%.0f", otherdevices_winddir[WindMeter])
   WU_URL = WU_URL .. "&windspeedmph=" .. string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
   WU_URL = WU_URL .. "&windgustmph=" .. string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end

-- if UVMeter ~= '' then
--    WU_URL = WU_URL .. "&UV=" .. string.format("%.1f", (otherdevices_uv[UVMeter]))
-- end

--&weather=
--&clouds=

WU_URL = WU_URL .. "&softwaretype=" .. SoftwareType .. "&action=updateraw"

print (WU_URL)

commandArray = {}

--remove -- before the line below to actually upload
--commandArray['OpenURL']=WU_URL

return commandArray