# User variables $MACaddress = "EC:FA:BC:80:73:93" # MAC address to spesific unit $APIkey = "e8f7be3fd6f54b2294cb7439f0ebcd6454fcac6059144ae2a025272733493c98" # Your API key $OutputDir = "C:\Cumulus\" # Code starts here $ApplicationKey = "bf597b5bc17141e79a2d9177b813a3659cf3a6029e714353842a09e9135c0925" # DO NOT EDIT! $rawdata = Invoke-WebRequest -UseBasicParsing "https://api.ambientweather.net/v1/devices?apiKey=$($APIkey)&applicationKey=$($ApplicationKey)&endDate=&limit=1" if (!$rawdata) { exit } $ProcessedData = Convertfrom-Json $rawdata $ProcessedData = $ProcessedData | where {$_.macaddress -eq "$MACaddress"} | select -ExpandProperty lastdata #$ProcessedData= $ProcessedData[0].lastdata # Mapping fields $time = $ProcessedData.date $Field3 = Get-Date $time -Format "yyyy-MM-dd" $Field4 = Get-Date $time -Format "HH:mm:ss" $Field6 = $ProcessedData.humidityin $Field7 = $ProcessedData.tempinf $Field8 = $ProcessedData.humidity #$Field8 = "50" $Field9 = $ProcessedData.tempf $Field10 = $ProcessedData.dewpoint $Field11 = $null $Field13 = $ProcessedData.baromrelin $Field14 = $ProcessedData.windspeedmph $Field16 = $ProcessedData.windgustmph [int]$Field19 = $ProcessedData.winddir $Field23 = $ProcessedData.hourlyrainin $Field27 = $ProcessedData.totalrainin $Field28 = $ProcessedData.solarradiation $Field29 = $ProcessedData.uv # Conversions $Field7 = ($Field7 - 32) * 5/9 # *F to *C $Field7 = [math]::Round($Field7,2) $Field9 = ($Field9 - 32) * 5/9 # *F to *C $Field9 = [math]::Round($Field9,2) $Field10 = ($Field10 - 32) * 5/9 # *F to *C $Field10 = [math]::Round($Field10,2) $Field13 = $Field13 * 33.8639 # inHg to millibar $Field14 = $Field14 * 1/2.23693629 # mph to m/s $Field14 = [math]::Round($Field14,3) $Field16 = $Field16 * 1/2.23693629 # mph to m/s $Field16 = [math]::Round($Field16,3) $Field23 = $Field23 * 25.4 # Inches to mm $Field27 = $Field27 * 25.4 # Inches to mm [int]$Field28 = $Field28 / 0.0079 # Maybe good enough W/m2 to lux # Wind direction degrees to text switch ($Field19) { {$_ -ge 0 -and $_ -le 11.25} {$Field19_t = "N"} {$_ -ge 11.26 -and $_ -le 33.75} {$Field19_t = "NNE"} {$_ -ge 33.76 -and $_ -le 56.25} {$Field19_t = "NE"} {$_ -ge 56.26 -and $_ -le 78.75} {$Field19_t = "ENE"} {$_ -ge 78.76 -and $_ -le 101.25} {$Field19_t = "E"} {$_ -ge 101.26 -and $_ -le 123.75} {$Field19_t = "ESE"} {$_ -ge 123.26 -and $_ -le 146.25} {$Field19_t = "SE"} {$_ -ge 146.26 -and $_ -le 168.75} {$Field19_t = "SSE"} {$_ -ge 168.76 -and $_ -le 191.25} {$Field19_t = "S"} {$_ -ge 191.26 -and $_ -le 213.75} {$Field19_t = "SSW"} {$_ -ge 213.76 -and $_ -le 236.25} {$Field19_t = "SW"} {$_ -ge 236.26 -and $_ -le 258.75} {$Field19_t = "WSW"} {$_ -ge 258.76 -and $_ -le 281.25} {$Field19_t = "W"} {$_ -ge 281.26 -and $_ -le 303.75} {$Field19_t = "WNW"} {$_ -ge 303.76 -and $_ -le 326.25} {$Field19_t = "NW"} {$_ -ge 326.26 -and $_ -le 348.74} {$Field19_t = "NNW"} {$_ -ge 348.75 -and $_ -le 360} {$Field19_t = "N"} Default {"No matches"} } # Wind chill if ($Field9 -lt 33 -and $Field14 -ge 1.79) { $Field11 = 33 + (($Field9 - 33) * (0.55 + (0.417 * [Math]::sqrt($Field14)) - (0.0454 * $Field14))) } else { $Field11 = $Field9 } ## Final Result Write-host "$Field3,$Field4,$Field6,$Field7,$Field8,$Field9,$Field10,$Field11,$Field13,$Field14,$Field16,$Field19_t,$Field23,$Field27,$Field28,$Field29" "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