Inspired by an idea from my friend @RangerRick, this is a weird mashup of the NHL StatsWeb API and the Tesla API. Since I'm attending all Carolina Hurricanes games, driving my Model 3, I'd love for the car to be warmed up and ready to head home as soon as a Canes home game ends.
To that end, this little program watches the NHL API for a home game for my team. If there's a home game today, it's gone final, and my car is parked at the arena, it will send an API action to my car to turn on the climate control and set the navigation for home. That way, when I walk out to my car, it's warmed up and ready to head for home!
If the home team wins, it will also honk the horn and flash the lights in celebration!
If there's no home game today, it just quietly exits, to try again tomorrow.
You can use this for your own local team and arena - just set those in the configuration file and run it on your own Ruby-friendly server!
The easiest way to get tesla_puck up and running is by using Docker Compose. This will download Docker images, set everything up, and run the software.
To run tesla_puck with Docker Compose, you will need to create two files:
.env file with your configurationdocker-compose.yml file for Docker.You should be able to copy this file verbatim into a directory on your Docker-enabled system:
version: "3"
services:
redis:
image: "redis:4.0-alpine"
command: redis-server
volumes:
- "redis:/data"
website:
depends_on:
- "redis"
image: minter/tesla_puck:latest
command: bundle exec puma -e production config.ru
ports:
- "${WEB_PORT}:9292"
environment:
- REDIS_URL=redis://redis:6379/0
- WEB_PASSWORD=${WEB_PASSWORD}
sidekiq:
depends_on:
- "redis"
image: minter/tesla_puck:latest
command: bundle exec sidekiq -e production -C config/sidekiq.yml -g teslapuck -r /app/lib/tesla_puck.rb
env_file:
- ./.env
environment:
- REDIS_URL=redis://redis:6379/0
- TIME_ZONE=${TIME_ZONE}
volumes:
redis:
Then, add your .env file into the same directory that has docker-compose.yml (see the Configuration section below)
Once both files are in place, run: docker-compose up -d - that will pull the required images, start the servides, and run them in the background. The Sidekiq admin will be available on whichever port you set the WEB_PORT value to.
Clone this repository to your system.
Create a .env file or copy the .env.example file to .env and edit it for your values (see the Configuration section below)
Inside the checked-out repository, run: docker-compose up using the docker-compose.yml provided inside the repository.
The following technologies are required to build this:
Additionally, we recommend a web server that can load a Rack configuration (like Phusion Passenger) and something that can daemonize Sidekiq (like systemd if you're on Ubuntu)
Clone this repository to your system.
Install the required gems with Bundler
bundle install --without development
Copy .env.example to .env and edit the values to match your requirements (see below)
Configure systemd or your daemonizer of choice to run Sidekiq. An example is provided in examples/sidekiq-teslapuck.service
Configure Passenger or your web server of choice to serve up the Sidekiq web admin via Rack. An example for Passenger/Nginx is provided in examples/nginx-passenger.conf
The configuration lives in a file named .env in the root directory where you're running things. A sample is provided for you as .env.example, so that you can adjust to your particular needs.
Previously, tesla_puck used a file named config/environment.yml - that file is no longer loaded.
Configuration values are in the form:
CONFIGURATION_VARIABLE=value
The configuration options are as follows:
trueTZInfo format, so you'll want to pick one of these:
America/New_York - Eastern TimeAmerica/Chicago - Central TimeAmerica/Denver - Mountain TimeAmerica/Phoenix - Arizona's weird DST rulesAmerica/Los_Angeles - Pacific TimeThese are the team ID numbers required as part of NHL StatsWeb to pull game/team information.
| Team Name | Team ID |
|---|---|
| Anaheim Ducks | 24 |
| Arizona Coyotes | 53 |
| Boston Bruins | 6 |
| Buffalo Sabres | 7 |
| Calgary Flames | 20 |
| Carolina Hurricanes | 12 |
| Chicago Blackhawks | 16 |
| Colorado Avalanche | 21 |
| Columbus Blue Jackets | 29 |
| Dallas Stars | 25 |
| Detroit Red Wings | 17 |
| Edmonton Oilers | 22 |
| Florida Panthers | 13 |
| Los Angeles Kings | 26 |
| Minnesota Wild | 30 |
| Montréal Canadiens | 8 |
| Nashville Predators | 18 |
| New Jersey Devils | 1 |
| New York Islanders | 2 |
| New York Rangers | 3 |
| Ottawa Senators | 9 |
| Philadelphia Flyers | 4 |
| Pittsburgh Penguins | 5 |
| St. Louis Blues | 19 |
| San Jose Sharks | 28 |
| Seattle Kraken | 55 |
| Tampa Bay Lightning | 14 |
| Toronto Maple Leafs | 10 |
| Vancouver Canucks | 23 |
| Vegas Golden Knights | 54 |
| Washington Capitals | 15 |
| Winnipeg Jets | 52 |
This code currently just grabs the first Tesla out of your account. If you have more than one Tesla: First, congratulations. Second, the code may need to be updated to get the correct car for you.
It would be nice if we could get the time zone of the game venue, but the NHL API does not provide that. It's only provided for the team. So it's possible that oddly-scheduled games might not work properly if the game is finishing "tomorrow" in your time zone.
Content type
Image
Digest
Size
198.9 MB
Last updated
almost 5 years ago
docker pull minter/tesla_puck