If you have a wind station working in Domoticz then you can connect your station using Windguru upload API with this script. Before you start uploading data, you must register your station in Windguru, choose "Other (upload API)" as station type here: https://stations.windguru.cz/register.php?id_type=16
The script must be configured with your wind station Domoticz device number, your windguru station ID and password.
Important, the wind data must be sent in knots.
Important: this script only works on linux type systems with an available md5sum executable, in my case a raspberry.
Script:
Code: Select all
--Device attributes: wind.speed, wind.gust, wind.direction, wind.directionString
return
{
on =
{
devices =
{
295, --script is executed every change of state of the weather station, must be your wind station device number
},
},
logging =
{
level = domoticz.LOG_ERROR,
marker = 'windGuru',
},
execute = function(dz, item)
local wind = item -- your wind station device number, wind station have to work with knots units
local uid = 'your_id' -- your Windguru station id
local station_pass = 'your_pass' -- your Windguru station password
local time_stamp = dz.time.dDate
local wind_speed = dz.utils.round(wind.speed,2)
local wind_gust = dz.utils.round(wind.gust*1.943,2)
local wind_direction = math.floor(wind.direction)
local wind_directionString = wind.directionString
local mySecret = time_stamp .. uid .. station_pass
local function osCommand(cmd)
dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)
local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
if commandOutput:find '::ERROR::' then -- something went wrong
dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
else -- all is fine!!
dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
end
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
local hash = osCommand('echo -n ' .. mySecret .. ' | md5sum'):match("(%w+)")
dz.log("md5Hash of " ..mySecret .. " is " .. hash , dz.LOG_DEBUG )
dz.openURL( 'http://www.windguru.cz/upload/api.php?uid='..uid..'&salt='..time_stamp..'&hash=' ..
hash..'&wind_avg='..wind_speed..'&wind_max='..wind_gust..'&wind_direction='..wind_direction)
end
}
More info: https://stations.windguru.cz/upload_api.php
Kind regards.