From Beige Wigeon, 5 Years ago, written in PowerShell.
Embed
  1. # User variables
  2. $MACaddress = "EC:FA:BC:80:73:93" # MAC address to spesific unit
  3. $APIkey = "e8f7be3fd6f54b2294cb7439f0ebcd6454fcac6059144ae2a025272733493c98" # Your API key
  4. $OutputDir = "C:\Cumulus\"
  5.  
  6.  
  7. # Code starts here
  8. $ApplicationKey = "bf597b5bc17141e79a2d9177b813a3659cf3a6029e714353842a09e9135c0925" # DO NOT EDIT!
  9. $rawdata = Invoke-WebRequest -UseBasicParsing "https://api.ambientweather.net/v1/devices?apiKey=$($APIkey)&applicationKey=$($ApplicationKey)&endDate=&limit=1"
  10.  
  11. if (!$rawdata) {
  12.  exit
  13. }
  14.  
  15.  
  16. $ProcessedData = Convertfrom-Json $rawdata
  17.  
  18. $ProcessedData = $ProcessedData | where {$_.macaddress -eq "$MACaddress"} | select -ExpandProperty lastdata
  19. #$ProcessedData= $ProcessedData[0].lastdata
  20.  
  21. # Mapping fields
  22. $time = $ProcessedData.date
  23. $Field3 = Get-Date $time -Format "yyyy-MM-dd"
  24. $Field4 = Get-Date $time -Format "HH:mm:ss"
  25. $Field6 = $ProcessedData.humidityin
  26. $Field7 = $ProcessedData.tempinf
  27. $Field8 = $ProcessedData.humidity
  28. #$Field8 = "50"
  29. $Field9 = $ProcessedData.tempf
  30. $Field10 = $ProcessedData.dewpoint
  31. $Field11 = $null
  32. $Field13 = $ProcessedData.baromrelin
  33. $Field14 = $ProcessedData.windspeedmph
  34. $Field16 = $ProcessedData.windgustmph
  35. [int]$Field19 = $ProcessedData.winddir
  36. $Field23 = $ProcessedData.hourlyrainin
  37. $Field27 = $ProcessedData.totalrainin
  38. $Field28 = $ProcessedData.solarradiation
  39. $Field29 = $ProcessedData.uv
  40.  
  41.  
  42. # Conversions
  43. $Field7 = ($Field7 - 32) * 5/9 # *F to *C
  44. $Field7 = [math]::Round($Field7,2)
  45. $Field9 = ($Field9 - 32) * 5/9 # *F to *C
  46. $Field9 = [math]::Round($Field9,2)
  47. $Field10 = ($Field10 - 32) * 5/9 # *F to *C
  48. $Field10 = [math]::Round($Field10,2)
  49. $Field13 = $Field13 * 33.8639 # inHg to millibar
  50. $Field14 = $Field14 * 1/2.23693629 # mph to m/s
  51. $Field14 = [math]::Round($Field14,3)
  52. $Field16 = $Field16 * 1/2.23693629 # mph to m/s
  53. $Field16 = [math]::Round($Field16,3)
  54. $Field23 = $Field23 * 25.4 # Inches to mm
  55. $Field27 = $Field27 * 25.4 # Inches to mm
  56. [int]$Field28 = $Field28 / 0.0079 # Maybe good enough W/m2 to lux
  57.  
  58.  
  59. # Wind direction degrees to text
  60. switch ($Field19) {
  61.     {$_ -ge 0 -and $_ -le 11.25} {$Field19_t = "N"}
  62.     {$_ -ge 11.26 -and $_ -le 33.75} {$Field19_t = "NNE"}
  63.     {$_ -ge 33.76 -and $_ -le 56.25} {$Field19_t = "NE"}
  64.     {$_ -ge 56.26 -and $_ -le 78.75} {$Field19_t = "ENE"}
  65.     {$_ -ge 78.76 -and $_ -le 101.25} {$Field19_t = "E"}
  66.     {$_ -ge 101.26 -and $_ -le 123.75} {$Field19_t = "ESE"}
  67.     {$_ -ge 123.26 -and $_ -le 146.25} {$Field19_t = "SE"}
  68.     {$_ -ge 146.26 -and $_ -le 168.75} {$Field19_t = "SSE"}
  69.     {$_ -ge 168.76 -and $_ -le 191.25} {$Field19_t = "S"}
  70.     {$_ -ge 191.26 -and $_ -le 213.75} {$Field19_t = "SSW"}
  71.     {$_ -ge 213.76 -and $_ -le 236.25} {$Field19_t = "SW"}
  72.     {$_ -ge 236.26 -and $_ -le 258.75} {$Field19_t = "WSW"}
  73.     {$_ -ge 258.76 -and $_ -le 281.25} {$Field19_t = "W"}
  74.     {$_ -ge 281.26 -and $_ -le 303.75} {$Field19_t = "WNW"}
  75.     {$_ -ge 303.76 -and $_ -le 326.25} {$Field19_t = "NW"}
  76.     {$_ -ge 326.26 -and $_ -le 348.74} {$Field19_t = "NNW"}
  77.     {$_ -ge 348.75 -and $_ -le 360} {$Field19_t = "N"}
  78.     Default {"No matches"}
  79.     }
  80.  
  81.  
  82. # Wind chill
  83. if ($Field9 -lt 33 -and $Field14 -ge 1.79) {
  84.     $Field11 = 33 + (($Field9 - 33) * (0.55 + (0.417 * [Math]::sqrt($Field14)) - (0.0454 * $Field14)))
  85.     }
  86. else {
  87.     $Field11 = $Field9
  88.     }
  89.  
  90.  
  91.  
  92. ## Final Result
  93.  
  94. Write-host "$Field3,$Field4,$Field6,$Field7,$Field8,$Field9,$Field10,$Field11,$Field13,$Field14,$Field16,$Field19_t,$Field23,$Field27,$Field28,$Field29"
  95.  
  96. "0,0,0,$Field3,$Field4,0,$Field6,$Field7,$Field8,$Field9,$Field10,$Field11,0,$Field13,$Field14,0,$Field16,0,0,$Field19_t,0,0,0,$Field23,0,0,0,$Field27,$Field28,$Field29" | out-file -Append $OutputDir\easyweatherplus.dat
  97.  
  98.  
  99.