MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. drippyer
    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 1
    • Posts 5
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Use .JSON as a module config value?

      @sdetweil I might have been a bit unclear haha. The break was pm2 no longer watching config.js, not a loop. My bad about that misunderstanding.

      posted in Troubleshooting
      drippyerD
      drippyer
    • RE: Use .JSON as a module config value?

      @sdetweil Thanks for the info!

      Ok, I see. That could definitely work.

      I went ahead and scrapped the code from above and converted it to a bash script that is executed before the cd ./MagicMirror (pretty sure I’ve had this setup running since before installers/mm.sh was actually provided lol). I admit the bash script is suuuper rough and was written with my symlinked config files in mind but it gets the job done!

      1. makes an intermediate copy of config.js
      2. grabs the content of the of the json
      3. declares variable containing config variable to be replaced
      4. prepends the variable string to the json content
      5. uses perl/regex to search for the variable in the intermediate file and replace it
      6. makes a backup of config.js just in case
      7. moves intermediate copy to working version
      #!/bin/bash
      
      cp /home/pi/mmConfig/config.js /home/pi/mmConfig/config.inter
      
      mapfile < /home/pi/mmConfig/user_list.json
      
      variableName="userNameFilter"
      
      replace="${variableName}: ${MAPFILE[@]}"
      
      perl -0777 -pi -e "s/${variableName}: {((.|\n)*?)}/${replace}/g" /home/pi/mmConfig/config.inter
      
      mv --backup=numbered /home/pi/mmConfig/config.js /home/pi/mmConfig/config_backups
      
      mv /home/pi/mmConfig/config.inter /home/pi/mmConfig/config.js
      

      And that successfully allows for the data to be read in! Thank you!

      Sadly, it did break pm2 watching config (which kinda makes sense to avoid a loop) and if I’m modifying the config I’m already in the command line and a pm2 restart mm isn’t too bad I suppose ¯\_(ツ)_/¯

      Edit: I’m realizing I should add a check to make sure it doesn’t perform either mv if the file is the same. New to-do lol!

      posted in Troubleshooting
      drippyerD
      drippyer
    • RE: MMM-RAIN-MAP

      @N6NG Assuming you are using jalibu/MMM-RAIN-MAP, the options in the README has the following info:

      `Option to use an alternative map. In most cases you are fine with the default but you can find more maps` here.
      
      Type: string
      Default value: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
      Alternative uncolored map: 'https://tiles.wmflabs.org/bw-mapnik/${z}/${x}/${y}.png'
      

      With here pointing at the Tile Servers wikipedia.

      It seems to me that the expected usage is to leave the {s}, {x}. {y}, and {z} alone.

      posted in Utilities
      drippyerD
      drippyer
    • Use .JSON as a module config value?

      Hey there!

      I am trying to automate a super small part of my MagicMirror which involves the MMM-PlexNowPlaying module.

      Basically, I’m trying to take a JSON file from the filesystem, read it to a JS Object, then use that Object as the value for the userNameFilter key within the config Object.


      Code

      This is the code I’ve made and added to my config.js to avoid writing an entire module lol:

      if (typeof module !== "undefined") {
          var plexUsers = require('/home/pi/mmConfig/user_list.json');
      
              let obj = config.modules.find((o, i) => {
                      if (o.module === "MMM-PlexNowPlaying") {
                              config.modules[i].config.userNameFilter = plexUsers;
                              return true; // stop searching
                      }
              });
      
              let test = config.modules.find(o => o.module === "MMM-PlexNowPlaying");
              console.log(test);
      }
      

      It’s located between var config = {}; and
      if (typeof module !== "undefined") {module.exports = config;}


      Confusion

      The two scenarios I have compared against each other are

      1. running the code above without
      2. commenting out let obj = {}; and hardcoding the Object (the normal way)

      And in both cases the output of test is the exact same. Yet the behavior of the Mirror doesn’t seem to reflect that. The standard usage of 2 works as expected, yet 1 does

      Any and all help would be greatly appreciated!

      posted in Troubleshooting
      drippyerD
      drippyer
    • RE: MMM-DarkSkyForecast - Yet ANOTHER weather module

      Just wanted to let folks know that DarkSky is no longer accepting new users to the API now that they have been acquired by Apple.

      posted in Utilities
      drippyerD
      drippyer
    • 1 / 1