Page 1 of 1

Script to import CumulusMX Data from an http call

Posted: Friday 19 February 2016 19:00
by bigmacd
I have a weather station sitting on an old Raspberry Pi B running CumulusMX.
The following call returns all the output data:

Code: Select all

http://<ip>:8998/api/data/currentdata


Quite a lot of information:

Code: Select all

{"AlltimeHighPressure":"1043.6","AlltimeLowPressure":"981.0","AppTemp":"2.8","AvgTempToday":3.9326086956521555,"Avgbearing":140,"Bearing":180,"BearingRangeFrom10":130,"BearingRangeTo10":180,"Build":"3036","Cloudbase":496,"CloudbaseUnit":"ft","CurrentSolarMax":0,"DataStopped":false,"DominantWindDirection":"SE","Forecast":"Showery, becoming less settled","HeatIndex":"7.3","HighAppTempToday":"4.6","HighAppTempTodayTime":"12:26","HighBeaufortToday":"F3","HighDewpointToday":"6.1","HighDewpointTodayTime":"17:32","HighGustBearingToday":135,"HighGustToday":"16","HighGustTodayTime":"17:35","HighHeatIndexToday":"9.0","HighHeatIndexTodayTime":"12:25","HighHourlyRainToday":"0.0","HighHourlyRainTodayTime":"00:06","HighHumToday":92,"HighHumTodayTime":"09:06","HighPressToday":"1024.3","HighPressTodayTime":"00:56","HighRainRateToday":"0.0","HighRainRateTodayTime":"00:06","HighSolarRadToday":0,"HighSolarRadTodayTime":"00:06","HighTempToday":"9.0","HighTempTodayTime":"12:25","HighUVindexToday":"0.0","HighUVindexTodayTime":"00:06","HighWindToday":"12","Humidex":"7.0","IndoorHum":68,"IndoorTemp":"12.5","LastDataRead":"17:42:59","LastRainTipISO":"2016-02-17 14:38","LowAppTempToday":"-2.8","LowAppTempTodayTime":"06:16","LowDewpointToday":"-2.2","LowDewpointTodayTime":"04:46","LowHumToday":71,"LowHumTodayTime":"12:26","LowPressToday":"1014.2","LowPressTodayTime":"17:18","LowTempToday":"0.4","LowTempTodayTime":"04:46","LowWindChillToday":"-1.3","LowWindChillTodayTime":"06:16","Moonrise":"14:21","Moonset":"05:09","OutdoorDewpoint":"6.1","OutdoorHum":92,"OutdoorTemp":"7.3","PressTrend":"-1.2","PressUnit":"mb","Pressure":"1014.4","RainLastHour":"0.0","RainMonth":"57.3","RainRate":"0.0","RainToday":"0.0","RainUnit":"mm","RainYear":"125.1","RainYesterday":"0.0","Recentmaxgust":"16","SolarRad":0,"StormRain":"0.0","StormRainStart":"-----","Sunrise":"07:19","Sunset":"17:31","SunshineHours":"0.0","TempTrend":"-0.1","TempUnit":"°C","UVindex":"0.0","Version":"3.0.0","WindAverage":"11","WindChill":"4.1","WindLatest":"12","WindRoseData":"0,0,46,0,712,1061,10336,521,4638,0,220,1,0,0,0,0","WindRunToday":"100.4","WindUnit":"mph"}
I have written the following code to update a few idxs: (first go at lua and not pretty!)

Code: Select all

print("Load CMX data ".._VERSION.."=".."!\n")
local idxthp = 32 --idx of the virtual sensor you need to change this to your own Device IDx
local idxt = 30
local idxh = 31

commandArray = {}
--if devicechanged[sensorwu] then
if true then
        -- create file of values from CumulusMX (Change IP address to suit your system)
        os.execute('curl "http://<ip>:8998/api/data/currentdata" > /home/pi/CMX.txt')
        -- one long line
        for line in io.lines("/home/pi/CMX.txt") do
                t = {}
                s = line
                -- find value pairs on pattern match
                for k, v in string.gmatch(s, '(%w+)":"(%w+)') do
                        -- Load array of values keyed by the value name
                        t[k] = v
                        -- undo rem line below to print all values to the log
                        -- print(k.."="..v)
                end
                for k, v in string.gmatch(s, '(%w+)":(%w+)') do
                        -- Load array of values keyed by the value name
                        t[k] = v
                        -- undo rem line below to print all values to the log
                        -- print(k.."="..v)
                end
                varstr="WindRunToday"
                --print(varstr.."="..t[varstr].."miles")
        end
        --TEMP;HUM;HUM_STAT;BAR;BAR_FOR
        IndoorTemp=t["IndoorTemp"]
        IndoorHum=t["IndoorHum"]
        Pressure=t["Pressure"]
        PressTrend=t["PressTrend"]
        print(IndoorTemp,IndoorHum,Pressure,PressTrend)

        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. IndoorTemp}
        commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. IndoorHum .. "|0" }
        commandArray[3] = {['UpdateDevice'] = idxthp .. '|0|' .. IndoorTemp .. "|" .. IndoorHum .. "|0|" .. Pressure .. "|0" }
end
return commandArray
If anyone is interested I would be pleased for some help improving this.

What are the humidity and weather devices looking for in the 0 place holders?

I know the file handling is poor and there must be a better way of loading the t[] array given the nature of the data.

All advice much appreciated.

TXs to the author of the weather Underground parser for many ideas. :)

Re: Script to import CumulusMX Data from an http call

Posted: Thursday 02 April 2020 21:03
by hve22
Hi,

At the momemt i'm looking for a script to get my CUMULUSMX data into Domoticz,
SO i came across your solution.

Question: Did you upgraded you script and if so can you share this??

With regards

Re: Script to import CumulusMX Data from an http call

Posted: Thursday 16 April 2020 15:55
by bewo
I think the output shown is an "normal" json string. So it's no problem to read and update devices. The script above has to be updated urgent. An "if true" argument is - in my opinion - an "programming ghost train".

What informations should be updated? Only temperature, humidity and pressure as in the script above?