Micheal_N_Blackwell
n3wb
Ok, I've included my procedure for adding weather overlay on to my BI Camera's.. The procedure once setup is pretty simple but if you haven't done this before, I hope my procedures help you.
How to insert Weather Data into BI Camera overlays
Note: I use the “ ” double quotes within this procedure to denote what to expected and the quotes should not be added to the text enclosed, however there is an exception and that's associated with the PowerShell Script file, it uses double quotes within the code, so instead I used "* " (star) character delimiter to denoted items between * xyz * star character that needs to be changed to reflect your circumstances, once you've update the file ensure that you've remove all of the (star) character(s).
Setting up the Necessary Directories
Run PowerShell
From the Windows Start Menu
PowerShell Error type I
Note: If this is your first-time running PowerShell you will most likely not be able to run Scripts (you will get an error message letting you know) as Windows is turned off by default, to fix this you must do the following (one-time event);
Download a new copy of PowerShell and "Bob's your Uncle!" it worked as advertised.. the many mysteries of Windows.....
To install or update the PowerShell app using Microsoft Store, use the following steps:
Run Task Scheduler
From the Windows Start Menu
Click Start, type Task Scheduler, and then click Task Scheduler.
You should now have a Task Scheduler Panel. On the right side in the action panel select “Create Task” you should now have a Create a Task dialog screen
Blue Iris Overlay Process
File content (Details), I've also attached the two files in question within a zipped file.
“My BI Overlay.Bat” contains the following command (it runs PowerShell with the appropriate Script);
“Pulling the weather data script for BI.ps1” contains the following commands: (Note: you will have to change the contents between * * characters with your particulars and make sure to delete the * as they are only visual delimiter for you)
How to insert Weather Data into BI Camera overlays
Note: I use the “ ” double quotes within this procedure to denote what to expected and the quotes should not be added to the text enclosed, however there is an exception and that's associated with the PowerShell Script file, it uses double quotes within the code, so instead I used "* " (star) character delimiter to denoted items between * xyz * star character that needs to be changed to reflect your circumstances, once you've update the file ensure that you've remove all of the (star) character(s).
Setting up the Necessary Directories
- You need to create a two directories' one for your “My BI Overlay.Bat” and “Pulling the weather data script for BI.ps1” PowerShell script files and the second for your updating weather Info text file.
- Open file explorer and navigate to This PC > C: (your C: drive).
- Using your mouse right click on the explore screen to get "New" option > Folder, Rename the new folder to "BI"
- Double click the "BI" directory, you should have a empty folder
- Using your mouse right click on the explore screen to get "New" option > Folder, Rename the new folder to "TXT" (this is where your updated weather text file will be stored).
- Place both “My BI Overlay.Bat” and “Pulling the weather data script for BI.ps1” files within the C:\BI directory.
- Make the necessary changes within the “Pulling the weather data script for BI.ps1” file, look for the * (star) characters this is where you will have to change the contents between * * (star) characters with your particulars and make sure to delete the * (star) characters as they are only visual delimiters for you.
Run PowerShell
From the Windows Start Menu
- Click Start, type PowerShell, and then click Windows PowerShell,
- You should now have a "Windows PowerShell" Window open with the cursor waiting for input.
- Manual Go/NO-GO testing: enter the following text below, followed depressing "Enter" or Return key.
Code:
& 'C:\BI\Pulling the weather data script for BI.ps1'
- You should get the following message displayed "The operation completed successfully." along with scrolling weather-related information if so then you're working!! proceed to Run Task Scheduler, otherwise...
- I have an Error Message (you can scroll up/down) displayed, try to determine if it's 1) "Unable to run PowerShell scripts or 2) Can't find "Condition" command that is used within the Scrapper code for Weather Condition.
- If you have determined that its Error 1) then proceed to PowerShell Error type I resolution.
- If you have determined that its Error 2) then proceed to PowerShell Error type II Resolution.
PowerShell Error type I
Note: If this is your first-time running PowerShell you will most likely not be able to run Scripts (you will get an error message letting you know) as Windows is turned off by default, to fix this you must do the following (one-time event);
- First, Open PowerShell with Run as Administrator
- Then, run this command (below) within the command line and depress enter:
Code:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- After that Type “Y” and Press Enter
- You will now be able to run PowerShell scripts.
- Proceed to "Run Task Scheduler" process.
Download a new copy of PowerShell and "Bob's your Uncle!" it worked as advertised.. the many mysteries of Windows.....
To install or update the PowerShell app using Microsoft Store, use the following steps:
- Open the Microsoft Store app (icon) on your PC.
- Use the search bar at the top to locate the PowerShell app on the store.
- Click the Update / Get button to update / Get the PowerShell app.
- Proceed to "Run Task Scheduler" process.
Run Task Scheduler
From the Windows Start Menu
Click Start, type Task Scheduler, and then click Task Scheduler.
You should now have a Task Scheduler Panel. On the right side in the action panel select “Create Task” you should now have a Create a Task dialog screen
- Enter “BI Weather Overlay” in the Name: field,
- Select “Next”, you will now have “Task Trigger” select “New”
- You should now have “New Trigger” screen, make sure that “Daily” is selected.
- Select “Repeat task every:” and change the drop down to “15 minutes”
- Select “for a duration of:” and change the drop down to “Indefinitely”
- Select “OK”, you should have a newly created Trigger.
- Select Actions Tab followed by “New” you should have a New Action with Action: set to “Start a program” selected if not change to reflect it.
- In the Program/Script: field enter “C:\BI\My BI Overlay.bat”
- You now have a working Task Scheduler that will execute your bat file every 15 minutes which will run your PowerShell script to create a new Weather.txt file output to be used in Blue Iris Overlays
Blue Iris Overlay Process
- In the Blue Iris app, goto Blue Iris Settings > Macros where you will see Macro %1 thru %9, change the first one “%1": and add "file:/C:\BI\Txt\Weather.txt" (not the " " characters)
- Goto the camera that you want to insert the overlay by right clicking the camera in question and selecting “Camera settings… > Video",
- Ensure that “Display overlays live” is selected,
- Goto “Edit overlays” select “Add text/time” at the top of Text overlay input field enter “%1”, you can change alignment to Left and set the Font Color to Yellow or whatever, depress enter.
- You can now move the "Weather overlay" to your desired placement by dragging with mouse and stretching to enlarge or reduce text size.
File content (Details), I've also attached the two files in question within a zipped file.
“My BI Overlay.Bat” contains the following command (it runs PowerShell with the appropriate Script);
Code:
@echo off
PowerShell -command "& 'C:\BI\Pulling the weather data script for BI.ps1'"
“Pulling the weather data script for BI.ps1” contains the following commands: (Note: you will have to change the contents between * * characters with your particulars and make sure to delete the * as they are only visual delimiter for you)
Code:
# /Pulling the weather data from two sources: Weather Underground, and weather.com, a string is formed with the requested data points.
# /wunderground is being html scraped for the condition shown on the site.
# /weather.com runs the API for Wunderground. It is pulling the time, temp, and wind conditions from the at-home wx station.
#
# /Create a registry value that should accept the silly cookie warning from wunderground.com... it gets deleted at the end of the script
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /t REG_DWORD /v 1A10 /f /d 0
#
# /SCRAPE THE WUNDERGROUND PAGE FOR THE CURRENT CONDITIONS
$UrlWUCond = "https://www.wunderground.com/weather/us/*Your State Abv*/*Your City*/*Your PW Station ID*"
$searchClass = "condition-icon small-6 medium-12 columns"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 <# using TLS 1.2 is vitally important #>
$req = Invoke-Webrequest -URI $UrlWUCond
$Condition = $req.ParsedHtml.getElementsByClassName($searchClass)[0].innertext;
#
# /POLL THE WEATHER.COM API TO GET THE CURRENT OBSERVATIONS
$UrlWU = "https://api.weather.com/v2/pws/observations/current?stationId=*Your PW Station ID*&format=json&units=e&apiKey=*Your WU API Key*"
$CurrentWeather = Invoke-RestMethod "$UrlWU"
$CurrentWeather | ConvertTo-Json -depth 100
#
# /CONVERT THE WIND AND COMPASS DIRECTION FROM THE WX STATION TO BE A UNICODE ARROW AND CARDINAL DIRECTION
# (i.e., wind out of the East will show an arrow pointing West, and the Cardinal direction):
#
if ($CurrentWeather.observations.winddir -gt 22.5 -and $CurrentWeather.observations.winddir -lt 67.5) {$arrow = $([char]0x2199)}
elseif ($CurrentWeather.observations.winddir -gt 67.5 -and $CurrentWeather.observations.winddir -lt 112.5) {$arrow = $([char]0x2190)}
elseif ($CurrentWeather.observations.winddir -gt 112.5 -and $CurrentWeather.observations.winddir -lt 157.5) {$arrow = $([char]0x2196)}
elseif ($CurrentWeather.observations.winddir -gt 157.5 -and $CurrentWeather.observations.winddir -lt 202.5) {$arrow = $([char]0x2191)}
elseif ($CurrentWeather.observations.winddir -gt 202.5 -and $CurrentWeather.observations.winddir -lt 247.5) {$arrow = $([char]0x2197)}
elseif ($CurrentWeather.observations.winddir -gt 247.5 -and $CurrentWeather.observations.winddir -lt 292.5) {$arrow = $([char]0x2192)}
elseif ($CurrentWeather.observations.winddir -gt 292.5 -and $CurrentWeather.observations.winddir -lt 337.5) {$arrow = $([char]0x2198)}
else {$arrow = $([char]0x2193)}
#
if ($CurrentWeather.observations.winddir -gt 11.25 -and $CurrentWeather.observations.winddir -lt 33.75) {$CardinalDir = "NNE"}
elseif ($CurrentWeather.observations.winddir -gt 33.75 -and $CurrentWeather.observations.winddir -lt 56.25) {$CardinalDir = "NE"}
elseif ($CurrentWeather.observations.winddir -gt 56.25 -and $CurrentWeather.observations.winddir -lt 78.75) {$CardinalDir = "ENE"}
elseif ($CurrentWeather.observations.winddir -gt 78.75 -and $CurrentWeather.observations.winddir -lt 101.25) {$CardinalDir = "E"}
elseif ($CurrentWeather.observations.winddir -gt 101.25 -and $CurrentWeather.observations.winddir -lt 123.75) {$CardinalDir = "ESE"}
elseif ($CurrentWeather.observations.winddir -gt 123.75 -and $CurrentWeather.observations.winddir -lt 146.25) {$CardinalDir = "SE"}
elseif ($CurrentWeather.observations.winddir -gt 146.25 -and $CurrentWeather.observations.winddir -lt 168.75) {$CardinalDir = "SSE"}
elseif ($CurrentWeather.observations.winddir -gt 168.75 -and $CurrentWeather.observations.winddir -lt 191.25) {$CardinalDir = "S"}
elseif ($CurrentWeather.observations.winddir -gt 191.25 -and $CurrentWeather.observations.winddir -lt 213.75) {$CardinalDir = "SSW"}
elseif ($CurrentWeather.observations.winddir -gt 213.75 -and $CurrentWeather.observations.winddir -lt 236.25) {$CardinalDir = "SW"}
elseif ($CurrentWeather.observations.winddir -gt 236.25 -and $CurrentWeather.observations.winddir -lt 258.75) {$CardinalDir = "WSW"}
elseif ($CurrentWeather.observations.winddir -gt 258.75 -and $CurrentWeather.observations.winddir -lt 281.25) {$CardinalDir = "W"}
elseif ($CurrentWeather.observations.winddir -gt 281.25 -and $CurrentWeather.observations.winddir -lt 303.75) {$CardinalDir = "WNW"}
elseif ($CurrentWeather.observations.winddir -gt 303.75 -and $CurrentWeather.observations.winddir -lt 326.25) {$CardinalDir = "NW"}
elseif ($CurrentWeather.observations.winddir -gt 326.25 -and $CurrentWeather.observations.winddir -lt 348.75) {$CardinalDir = "NNW"}
else {$CardinalDir = "N"}
#
$Time = get-date -format "MM/dd HH:mm:ss"
#
# /BLUEIRIS OVERLAY
# checks rainfall. Rain accumulation less than .05" is ignored. Finally, the string is combined to form the weather.txt file output.
if ($CurrentWeather.observations.imperial.precipTotal -ge 0.05) {$json = Write-Output "PWS:$($CurrentWeather.observations.stationID) `nCond:$($Condition) `nTemp: $($CurrentWeather.observations.imperial.temp)°F `nWind Chill: $($CurrentWeather.observations.imperial.windChill)°F `nHumidity: $($CurrentWeather.observations.humidity)% `nWind Speed: $($arrow)$($CurrentWeather.observations.imperial.windSpeed) mph $($CardinalDir) `nRainfall: $($CurrentWeather.observations.imperial.precipTotal)"" `nPressure: $($CurrentWeather.observations.imperial.pressure)"" `nUltraviolet (UV): $($CurrentWeather.observations.uv) `nLast Updated: $($Time)"}
#
else {$json = Write-Output "PWS:$($CurrentWeather.observations.stationID) `nCond:$($Condition) `nTemp: $($CurrentWeather.observations.imperial.temp)°F `nWind Chill: $($CurrentWeather.observations.imperial.windChill)°F `nHumidity: $($CurrentWeather.observations.humidity)% `nWind Speed: $($arrow)$($CurrentWeather.observations.imperial.windSpeed) mph $($CardinalDir) `nRainfall: $($CurrentWeather.observations.imperial.precipTotal)"" `nPressure: $($CurrentWeather.observations.imperial.pressure)"" `nUltraviolet (UV): $($CurrentWeather.observations.uv) `nLast Updated: $($Time)"}
$json | Out-File -FilePath "C:\BI\TXT\weather.txt" -Encoding UTF8
clv -Name Condition
#
# Delete the registry value
reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v 1A10 /f
exit
Attachments
Last edited: