• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MRX-Work-Traffic - Shows the time you need to get to work

Scheduled Pinned Locked Moved Transport
9 Posts 3 Posters 5.4k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    domsen123
    last edited by domsen123 Mar 17, 2017, 9:07 AM Mar 17, 2017, 9:04 AM

    Description:

    Hey ho,
    I wrote my first module wich is showing the current time to my workplace.
    You can add more than one.
    I think, its not the best code at all… but it works :)
    Uses google REST API to get the details…

    Screenshot

    0_1489741327810_Screen.PNG

    Download:

    [card:domsen123/mrx-work-traffic]

    S 1 Reply Last reply Mar 17, 2017, 9:34 AM Reply Quote 0
    • S Offline
      strawberry 3.141 Project Sponsor Module Developer @domsen123
      last edited by Mar 17, 2017, 9:34 AM

      @domsen123 Interesting how you get in 11mins from Berlin to Hofbräuhaus in Munich :rofl:

      Please create a github issue if you need help, so I can keep track

      1 Reply Last reply Reply Quote 0
      • D Offline
        domsen123
        last edited by Mar 17, 2017, 9:54 AM

        haha this screen is with an other config :D

        Its from the Main Trainstation in Munich :)

        S 1 Reply Last reply Mar 17, 2017, 10:08 AM Reply Quote 0
        • S Offline
          strawberry 3.141 Project Sponsor Module Developer @domsen123
          last edited by strawberry 3.141 Mar 17, 2017, 10:09 AM Mar 17, 2017, 10:08 AM

          @domsen123 bummer thought you are probably related to captain kirk with access to warp speed

          Please create a github issue if you need help, so I can keep track

          D 1 Reply Last reply Mar 17, 2017, 10:12 AM Reply Quote 0
          • D Offline
            domsen123 @strawberry 3.141
            last edited by Mar 17, 2017, 10:12 AM

            @strawberry-3.141 thats the next module I will write (MMM-MagicBeam) with Alexa support…
            Mirror, beam me up to Oktoberfest…

            1 Reply Last reply Reply Quote 0
            • J Offline
              j.e.f.f Project Sponsor Module Developer
              last edited by Apr 29, 2017, 11:39 PM

              For the life of me, I can’t get this to work… I don’t even get the header label. Here’s what I did:

              1. Cloned the repo into my modules directory with
                git clone https://github.com/domsen123/mrx-work-traffic.git

              2. In the new directory first I tried to run npm install but I got the error that package.json didn’t exist. So I tried to install request directly by running npm install requestbut I got the same error.

              3. I tried creating package.json by running npm init. then I was able to install Request by running npm install request.

              4. I requested a Google API key from here:
                https://developers.google.com/maps/documentation/javascript/get-api-key

              5. My config looks like this:

                  {
                    module: 'mrx-work-traffic',
                    position: 'top_left',
                    header: 'Traffic',
                    config: {
                      apikey: '*** My API Key ***',
                      origin: '135 Bellefair Ave, Toronto ON M4L 3V1',
                      startTime: '00:00',
                      endTime: '23:59',
                      destinations: [
                        {
                          destination: '37 Holland Dr Bolton, ON L7E 5S4',
                          label: 'Mars'
                        }
                      ]
                    }
                  },    
              
              

              I don’t see any errors in the console. All I get on my screen is the header’s underline, but not even the label text.

              I suspect that the problem is either that Request is not installed properly, or that this won’t work with Canadian addresses. Any thoughts?

              Thanks!
              -Jeff

              1 Reply Last reply Reply Quote 0
              • D Offline
                domsen123
                last edited by May 2, 2017, 8:18 AM

                Hey j.e.f.f…

                1. clone in modules directory (remove the npm files you created through npm install)
                2. go back to root…
                3. type “npm install”, if “request” not installed yet (should be installed by default)
                4. request api key (you have already, looks good)

                your config looks good too…

                just to be sure, plz use :

                origin: 'Platz der Republik 1, 11011 Berlin',
                destinations: [
                			{
                				destination: 'Platzl 9, 80331 München',
                				label: 'Hofbräuhaus'
                			}
                		]
                

                But it shouldn’t be a problem, using Canadian addresses…

                J 2 Replies Last reply May 2, 2017, 12:39 PM Reply Quote 0
                • J Offline
                  j.e.f.f Project Sponsor Module Developer @domsen123
                  last edited by j.e.f.f May 2, 2017, 12:43 PM May 2, 2017, 12:39 PM

                  @domsen123 I followed your instructions and I still can’t get it to work for me.

                  I did a little digging into your code, and it seems like this line is evaluating to false every time:

                  mrx-work-traffic.js: Line 43

                  if( now >= this.config.startTime && now < = this.config.endTime )
                  

                  (space between < and = added by me. Otherwise it broke markdown…)

                  I added a console.log at line 57:

                  else{
                        console.log("====================== hiding...");
                        this.hide(0);
                  }
                  

                  and I see that in my console. It looks like now is not interpreted to be between config.startTime and config.endTime.

                  My config has them set as follows:

                          startTime: '00:00',
                          endTime: '23:59',
                  
                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    j.e.f.f Project Sponsor Module Developer @domsen123
                    last edited by May 2, 2017, 1:15 PM

                    @domsen123 A bit more hacking on this and I got it to work. I changed how the date comparison is done:

                        var now = moment();
                        var startTimeSplit = this.config.startTime.split(":");
                        var endTimeSplit = this.config.endTime.split(":");
                    
                        var startTime = moment().hour(startTimeSplit[0]).minute(startTimeSplit[1]);
                        var endTime = moment().hour(endTimeSplit[0]).minute(endTimeSplit[1]);
                    
                        if( now.isSameOrAfter(startTime) && now.isSameOrBefore(endTime) ){
                    
                    

                    I had to do this in three places:

                    1. in the start() function
                    2. in the getDom() function
                    3. in the getHeader() function

                    I’m no seasoned programmer, so I’m sure there is a better way to do this, but this at least works for me, and I can verify that Canadian addresses seem to work fine.

                    Any chance you can add a configuration to each destination for the travel mode? i.e.: Driving, Transit, Biking, Walking. I have two destinations currently configured, my wife’s commute, which she drives, and mine, for which I take transit. I’d like mine to show transit time, not driving time.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Enjoying MagicMirror? Please consider a donation!
                    MagicMirror created by Michael Teeuw.
                    Forum managed by Sam, technical setup by Karsten.
                    This forum is using NodeBB as its core | Contributors
                    Contact | Privacy Policy