Basic Weather Overly (Alternitive-ish)

Joined
Apr 3, 2021
Messages
2
Reaction score
2
Location
USA
I've recently been having issues with BI tools (causing slowdown, TLS update issue), and since I am only using it for weather overlay, I decided to see if I could find an alternative and was wondering if there is any interest in what I threw together.

First, I'm pretty much a n00b with BI so forgive me if this is a waste. I'm also not sure if installing BI Tools and running once and uninstalling (or just not running) is required, but I believe for my current setup it is. So, that's the first thing, I ran BI tools and checked to set temp data. My reason is I will be using the temperature.txt and %1 macro. I then uninstalled BI Tools. From here on out everything is just about modifying that txt file. So I have chosen to use OpenWeatherMap API and powershell to get the data I wanted.

Steps:
  1. Head over to Сurrent weather and forecast - OpenWeatherMap and sign up for their free API access to current weather data. This allows for 1,000,000 free API calls per month.
    1. If we poll every 10 seconds we would have a maximum of (on 31-day months): [(60 seconds/min) * (60 min/hr) * (24 hr/day) * (31 days/month)]/(1 Poll /10 seconds) = 267,840 calls per month.
      1. Note - You can modify the $pollSec value in Get-Weather.ps1 to change the poll frequency (in seconds)
    2. Copy the API key (sent via email when ready)
  2. Find your locations "CityID". Easiest way is to search for your city and then find the ID in the URL:
    1. EX: https:// openweathermap.org/city/5393052
  3. Grab the current scripts from here jamjen831/Get-Weather and place in C:\Scripts (or elsewhere and update paths in the script) :
    1. Get-Weather.psm1 is the module that contains the Get-Weather function that does all the actual work
    2. Get-Weather.ps1 is the script we run that calls the Get-Weather function (Get-Weather.psm1) every 10 seconds
  4. Enable Powershell scripts
    1. Open Powershell As Admin
    2. Run command "Set-ExecutionPolicy -Unrestricted"
  5. Edit Get-Weather.psm1 (Module\Function)
    1. Set $cityID to the City ID found in step 2.1
    2. Set $ apiKey with your API key from 1.2
  6. Setup Windows Scheduled Task to run every 5 minutes (The script repeats the function every 10 seconds for 4min 50 sec the quits*):
    1. Open Windows task Scheduler
    2. Right-Click on "Task Scheduler Library" and chose "Create task"
    3. General Tab: Select "Run whether user is logged on or not"
    4. Trigger Tab: Click New
    5. Setting: Daily
    6. Advanced Settings: Repeat Task Every: 5 minutes for Duration of: 1 day
    7. Check "enabled"
    8. Actions Tab: Click New
    9. Program script: Powershell.exe
    10. Add Argument: -File c:\script\Get-Weather.ps1 (or wherever you have placed the script)
    11. Save (you will likely be prompted for a username and password, this will be used to run the task
  7. Check the temperature.txt to make sure it's being updated, if not, check the persmissions for the file, as BI tools likes to lock write permissions.

*Why do it this way? Since I am using a script and using task scheduler (vs creating a service), we have no way to check if things have hung. By limiting the script to every 5 minutes (task scheduler min. re-run time) we can limit our potential time between auto-restart

 
Last edited:

concord

Getting comfortable
Joined
Oct 24, 2017
Messages
663
Reaction score
739
You mentioned Get-Weather.ps1, but didn't provide it...I see a few on github doing something similar. I use dark skys on home assistant, but it can be off by 5 degrees sometimes (Weather), need to check out openweathermap, thanks!
 

Vetra

n3wb
Joined
Apr 25, 2022
Messages
1
Reaction score
0
Location
USA
Thanks for this.

Been using OpenWeather for years to display in my Hubitat dashboards.

Had problems getting powershell to run from scheduler without a prompt. Seems that maybe ticking off the run hidden checkbox did the trick.

ENJOY
 
Top