MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. UncleRoger
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 16
    • Posts 106
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Config option with array of multiple values?

      @MZ-BER said in Config option with array of multiple values?:

      Hello @UncleRoger - are you planning to publish your module? And can I may ask you what this module will do?

      Yes, I am planning to publish it, once I’ve tested it reasonably well. Mostly, it seems to work thus far. I’m doing more testing and working on documentation.

      The module checks an e-mail address and then shows the subject of any e-mails on the MM. Basically, I wanted a way for my wife and I to post messages for the whole family to see. This is an idea I’ve had for a long time (going back to the days of pagers) and is kinda obsolete – we use text messages and instagram messages a lot these days – but I still wanted to make this happen.

      Probably next week I’ll be posting a message “how do I put a module in github for everyone to use?” as I’m totally new to all of this. 8^)

      posted in Development
      UncleRogerU
      UncleRoger
    • RE: Config option with array of multiple values?

      @UncleRoger said in Config option with array of multiple values?:

      subject = subject + selSender[0].color;
      // if (selSender[0].color != undefined) {
      subjectWrapper.style.color = selSender[0].color;
      // } else {

      Is there a reason it doesn’t like that in the IF statement? Note: I also tried it as just “if (selSender[0].color) {” and assigning the value of selSender[0].color to another variable and using that other variable in the IF statement. In at least one test case there is a value in color.

      Okay, so it looks like Javascript wants “!==”, not “!=”. Ugh.

      Anyway, I got it working using a “switch (true)” block.

      Thanks for all the help!

      posted in Development
      UncleRogerU
      UncleRoger
    • RE: Config option with array of multiple values?

      @sdetweil
      I got it working with the .filter function:

      let selSender = that.config.validSenders.filter(mySender => {
      	if (mySender.addr.toLowerCase() == mailObj.sender[0].address.toLowerCase()) 
      		return true
      	 else 
      		return false
      });
      

      but now I’m having a problem trying to use the returned array. In this code the adding the color element to the subject works fine (that’s there for testing), as does the setting the style.color, but if I uncomment the if statement, it crashes:

      subject = subject + selSender[0].color;
      //		if (selSender[0].color != undefined) {
      			subjectWrapper.style.color = selSender[0].color;
      //		} else {
      

      Is there a reason it doesn’t like that in the IF statement? Note: I also tried it as just “if (selSender[0].color) {” and assigning the value of selSender[0].color to another variable and using that other variable in the IF statement. In at least one test case there is a value in color.

      posted in Development
      UncleRogerU
      UncleRoger
    • RE: Config option with array of multiple values?

      @sdetweil said in Config option with array of multiple values?:

      maybe what you wanted was

      if (
           that.config.validSenders.includes(mailObj.sender[0].address) && 
          (daysAgo >= 0 && daysAgo <= that.config.daysToDisplay)  
           ) {
      

      this is two outer compares (with one inner)

      I just tried this and it works. Not sure why the extra set of parentheses are needed but I’m not going to argue. 8^)

      Thanks!

      posted in Development
      UncleRogerU
      UncleRoger
    • RE: Config option with array of multiple values?

      @sdetweil said in Config option with array of multiple values?:

      generally when you expand the number of items in an array to objects ({}) you start to get thinking about what happens if you decide to add another entry in the object…

      so in javascript you can NAME the elements

      validSenders: [ 
                      { url:"mom@example.com", name:"Mom", color:"#ff0000" },
                      { url"dad@example.com", name:"Dad", color:"#00ff00" },
                      { url:"son@example.com", name:"Son", color:"#0000ff" },
                    ]
      

      that way the code is not sensitive to the order of the elements

           validSenders.forEach(sender =>{
                   if (sender.name =="Dad") {
                        do_something(sender.url)
                   }
           })
      

      So in this scenario, you have validSenders the array and, for example, validSenders.url as one attribute(?) of the array? In your example, where does “sender” come from? It’s not one of the named elements. Is it a sort of temporary variable that gets handed the array … object(?) … so in the first iteration of the forEach (which I assume loops through each entry in the validSenders array), sender would contain(?) url:"mom@example.com", name:“Mom”, and color:“#ff0000”? And sender.url would be “mom@example.com”?

      That makes sense. I apologize for not knowing the terminology; I’m very new to the whole OOP sort of thing.

      you can also use the array.filter() function

      let selected_sender = validSenders.filter(sender=>{
            if(sender.url==mailObj.sender[0].address)
                 return true
           else
                 return false
       })
      if(selected_sender.length>0){
          // we found a matching sender
      }
      

      the filter function passes each element array in turn to the function
      if you want the element in the output array return true,
      if not return false

      Could this return false if it doesn’t match but an index if it matches so that one could refer to validSenders.color[selected_sender] to get the right attribute?

      I really kinda wish I had a spare RPi laying around so I could do this testing on something other than my production mirror. (I mean, everyone’s aware that it’s a work-in-progress but I don’t want to muck it up.)

      • that.config.validSenders.includes(mailObj.sender[0].address)
      • daysAgo >= 0
      • daysAgo <= that.config.daysToDisplay

      the last two CANNOT be true at the same time

      I’m not sure I understand… if daysToDisplay is, say, 50 and daysAgo = 25, then the last two would both be true?

      What I’m trying to do is make sure that the sender of an e-mail is in the list of valid senders and that the date the e-mail was sent is not more than daysToDisplay days ago.

      maybe what you wanted was

      if (
           that.config.validSenders.includes(mailObj.sender[0].address) && 
          (daysAgo >= 0 && daysAgo <= that.config.daysToDisplay)  
           ) {
      

      this is two outer compares (with one inner)

      I thought I tried that but even so, I don’t understand how that’s different from what I had. I thought that “If A && B && C” would be the same as “If A && (B && C)” – in either case, all three have to be true for the whole thing to be true.

      posted in Development
      UncleRogerU
      UncleRoger
    • Config option with array of multiple values?

      I’m working on a module and it mostly works. I’d like to expand its functionality a bit though and to do that I’m thinking about changing an array I have into an array of multiple values. That is, I currently have defined and am using:

      validSenders: [ "mom@example.com",
                      "dad@example.com",
                      "son@example.com",
                    ]
      

      My code uses it thusly:

      if (!that.config.validSenders || that.config.validSenders.includes(mailObj.sender[0].address)) {
      
      

      What I’d like to do is change that to look like this:

      validSenders: [ { "mom@example.com", "Mom", "#ff0000" },
                      { "dad@example.com", "Dad", "#00ff00" },
                      { "son@example.com", "Son", "#0000ff" },
                    ]
      

      but I don’t know a) if that’s right, b) how I would do the check in the if statement above, and c) how I would access the other parts of each element. Heck, I don’t even know if that syntax is right. (I know nothing of Javascript.)

      Any help with this would be much appreciated. It’s totally unnecessary but I think it could enhance the usability of the module for others.

      And if I might digress for a moment, I have this code in my module:

      if (that.config.validSenders.includes(mailObj.sender[0].address)) {
         if (daysAgo >= 0 && daysAgo <= that.config.daysToDisplay) {
      

      which works fine.

      But if I combine those two IF statements, it doesn’t.

      if (that.config.validSenders.includes(mailObj.sender[0].address) && \
          daysAgo >= 0 && daysAgo <= that.config.daysToDisplay) {
      

      It doesn’t work even if I remember to remove the second closing brace at the end.

      Thanks!

      posted in Development
      UncleRogerU
      UncleRoger
    • RE: Request for a dinner plan

      I don’t know if this will work for you but I’ve set up a google calendar called “Dinner Menu” that I use for planning meals for the week. I enter an all-day event for each day with the main dish and, occasionally, sides. Actually, I mostly duplicate previous events as I’ve put the ingredients in the description for most of the meals to help with planning the weekly shopping.

      I’m now setting up a MagicMirror and am using an instance of the stock calendar module to list the next 7 days of dinners. (One of the primary reasons for setting this up is to get my son to stop asking “What’s for dinner” every day.)

      Here’s what it looks like on the MM:

      012338d3-1a00-4ff4-8e71-8dcebbfb85a7-image.png

      Actually, that’s from a few days ago; I got rid of the icon on the left for a cleaner look. So far, it’s pretty much solved the problem and it’s not even properly set up yet.

      I haven’t looked into recipe modules yet; I might look for a calendar module that can show the description for an event to show today’s meal and the comments I’ve entered for it (usually a list of ingredients) but that’s down the road.

      posted in Requests
      UncleRogerU
      UncleRoger
    • RE: MMM-Moon shows only "No Image!"

      @sdetweil Thanks to a comment on another thread, I’ve found the answer – I needed to restart the RPi. Once I did that, both the MoonPhase and MMM-Earth modules started working.

      posted in Troubleshooting
      UncleRogerU
      UncleRoger
    • RE: MMM-Moon shows only "No Image!"

      I tried using MMM-MoonPhase and didn’t have any luck there either. Here is my config for that:

                      {
                              module: "MMM-MoonPhase",
                              position: "top_left",
                              config: {
                                      updateInterval: 43200000,
                                      hemisphere: "N",
                                      resolution: "detailed",
                                      basicColor: "white",
                                      title: true,
                                      phase: true,
                                      size: 200,
                                      moonAlign: "center",
                                      textAlign: "center",
                                      alpha: 0.7,
                                      riseAndSet: {
                                          display: false,
                                          lat: 37.xxxxx,
                                          lon: -122.xxxxx,
                                          gmtOffset: -8.0
                                      }
                              }
                      },
      

      Here’s what I’m seeing:
      84344962-5bf5-4b2c-852a-366ef454ae69-387451827_1708599592982589_729151378905253751_n.jpg

      I’m starting to think that maybe it’s something more basic with my setup as MMM-SystemStats doesn’t work either (just shows “Loading…” for each item).

      The moon phase isn’t, of course, critical, but it would be nice to get working.

      posted in Troubleshooting
      UncleRogerU
      UncleRoger
    • RE: Want to show full-screen images and switch to MM on keypress

      @sdetweil

      Oh dear. Looks like I’ve got my work cut out for me. 8^) I think I’ll see if I can dig up another RPi to use for testing so I don’t muck up the “production” one. 8^)

      Thanks for your help!

      posted in General Discussion
      UncleRogerU
      UncleRoger
    • 1
    • 2
    • 7
    • 8
    • 9
    • 10
    • 11
    • 10 / 11