Code Monkey home page Code Monkey logo

mmm-traffic's Introduction

MMM-Traffic

module screenshot

This a module for the MagicMirror. It displays travel time between two locations, using the Mapbox directions API to factor in current traffic conditions.

Table of Contents

Installation

Navigate into your MagicMirror's modules folder and execute these commands:

git clone https://github.com/SamLewis0602/MMM-Traffic.git
cd MMM-Traffic
npm install

Mapbox Access Token

  1. Create an account at Mapbox
  2. Copy the access token visible after account creation (go here if you don't see it)
    • Note: Google maps coordinates are latitude,longitude, but Mapbox uses longitude,latitude so be sure to reverse what you copy from Google.

Configuration

Required

Option Description Type Example
accessToken Mapbox access token string -
originCoords longitude,latitude of the origin location. string '-84.504259,33.882107'
destinationCoords longitude,latitude of the origin location. string '-84.504259,33.882107'

Basic Options

Option Description Type Default Value Supported Options
language Define the commute time language. string config.language Any language string
interval How often the traffic is updated in milliseconds. integer 300000
(5 minutes)
showSymbol Whether to show the car symbol or not. boolean true

Translation/Display

Use these options to customize/translate the module's text.

*Note: See tokens below to see what tokens will be replaced with real values in firstLine/secondLine.

Option Description Type Default Value Token Replacement
loadingText The text used when loading the initial duration. string 'Loading...'
firstLine The main line of the module string 'Current duration is {duration} mins' ✔️
secondLine The second line of the module, appears below the first line in smaller, dimmer text string undefined ✔️

Tokens

Token Value
{duration} The driving time returned from the mapbox API

Per Day/Time Customization

Using these options to hide the module when you're not using it will save API calls, allowing you to have a shorter interval or more MMM-Traffic modules without getting rate limited.

Option Description Type Default
days Which days of the week to show the traffic module, with 0 being Monday Array[int] [0, 1, 2, 3, 4, 5, 6]
hoursStart What time to begin showing the module on the days it shows, 24 hour time String "00:00"
hoursEnd What time to stop showing the module on the days it shows, 24 hour time String "23:59"

Examples

Simplest Config

{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
	}
},

simple config screenshot

Minimal Look

{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		showSymbol: false,
		firstLine: "{duration} mins"
	}
},

minimal screenshot

Use both lines

{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		firstLine: "{duration} mins",
		secondLine: "Coffee Run"
	}
},

both lines custom screenshot

Multiple Routes

{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		firstLine: "{duration} mins",
		secondLine: "Home To School",
	}
},
{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		firstLine: "{duration} mins",
		secondLine: "Home To Work"
	}
},

multiple routes screenshot

Per day customization

This setup would show one route for Monday, Wednesday, and Friday, and another for Tuesday and Thursday. It would only show between 07:00 and 09:00 each day. It would be completely hidden on weekends.

{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		firstLine: "{duration} mins",
		secondLine: "School",
		days: [0,2,4],
		hoursStart: "07:00",
		hoursEnd: "09:00"
	}
},
{
	module: "MMM-Traffic",
	position: "top_left",
	config: {
		accessToken: "your_key_here",
		originCoords: "-84.398848,33.755165",
		destinationCoords: "-84.504259,33.88210",
		firstLine: "{duration} mins",
		secondLine: "Work",
		days: [1,3],
		hoursStart: "07:00",
		hoursEnd: "09:00"
	}
},
Day View
Mon/Wed/Fri minimal screenshot
Tu/Th minimal screenshot

Dependencies

Legacy

If you want to continue using the old version with Google Maps and more customization, use the 1.0-not-supported branch.

NOTE: this version is no longer supported, please do not open issues on the repo if you run into issues with this version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.