MagicMirror² v2.8.0 is available! For more information about this release, check out this topic.

config.js in JSON format



  • Is it possible to change config.js file into JSON format for easy and smooth interchange between apps (for reading values from it and writing values to it)?.


  • Module Developer

    @Serge
    But when it is pure JSON, it will lose some benefit of using JS programmatic extensible features (e.g: callback function as values, conditional dynamic values on bootup, or any customized routines by user.)
    By example, I 'm using conditional disabled: to test and debug the modules. It could be done with pure JSON but could be somewhat annoying thing.


  • Module Developer

    Anyway, you can access other module’s config values with {module}.configon runtime. And if you need config values before bootup, you can just include config.js to your individual pre-processer program for reading config values. (Then you can write it also)



  • @Sean
    I am going to make external app to change all module parameters.
    What does I mean based on the “clock” module example:

    1. Сurrent config.js has the following settings for clock module:
    modules: [
    		{
    			module: "clock",
    			position: "top_left"
    		},
    ]
    
    1. I am adding all other clock’s parameters (taken from /modules/default/clock/clock.js) into config.js:
    modules: [
    {
    	    module: "clock",
                position: "top_left"
                config: {
                    displayType: "digital",
    		displaySeconds: true,
    		showPeriod: true,
    		showPeriodUpper: false,
    		clockBold: false,
    		showDate: true,
    		showWeek: false,
    		dateFormat: "dddd, LL",
    		analogSize: "200px",
    		analogFace: "simple", 
    		analogPlacement: "bottom",
    		analogShowDate: "top", 
    		secondsColor: "#888888",
    		timezone: null,		
    }, }, ]
    
    1. Parameters in config.js overwrites the parameters in clock.js, so it works fine in such way.
    2. I am going to make some external app (web-interface) to allow user to make changes in config.js (in file) and reload MM in order effect take place.
      This should be a similar to “MMM Remote control” module but different in functionality and in its logic - my app should change the file config.js).

    I need to consult with community how to make this in correct and simple way? At the moment I have a template based on SB Admin 2 (html bootstrap)


  • Project Sponsor

    I think I understand (and like!) what you are trying to do, but the downside is that you’re going to create one hell of a file. The module configs are in a lot of cases much bigger than what the module creator suggests users to change. The clock you’ve shown is a very good example.

    However, it might lead to a very promising function, so I’d be happy to support.

    I would very much like to see the web interface to be limited to layers with a drop-down function
    First layer: all installed modules.
    Click on a module -> open dropdown with all config parameters for this module.
    (Somehow) limit the possibilities to change config options to prevent semantic errors. E.g. for boolean parameters, the user should only be able to switch between true and false. String parameters should be converted to strings automatically. Numbers be parsed to number and so on…

    If you create a web interface that gives the user the possibility to easily change config options AND that prevents semantic errors (e.g. by checking the new input instantly).

    …then you’re the hero!!

    The more I write about it the more I like it…

    Is there somethin on github that I can have a look at already?



  • another mirror runtime uses jsonform, and a schema file provided by
    each module (exposing what the module wants configurable, and how), and then generates a web UI for all the info, provides a save function, which updates its config file and then restarts the app.

    I have created modules using this capability and also extended it on the base to allow module location placement (like mm position ) via dropdown selection.



  • @lavolp3 said in config.js in JSON format:

    I think I understand (and like!) what you are trying to do, but the downside is that you’re going to create one hell of a file. The module configs are in a lot of cases much bigger than what the module creator suggests users to change. The clock you’ve shown is a very good example.

    All other modules have + - the same number of parameters. config.js looks good and readable.
    Changes of module parameters do not affect functionality. They change appearence so if all parameters are inputed correctly (e.g. numbers to numbers, strings to strings) - everything will work fine.

    I would very much like to see the web interface to be limited to layers with a drop-down function
    First layer: all installed modules.
    Click on a module -> open dropdown with all config parameters for this module.

    I have some draft of the interface and it looks similar to those you have described. However, I drop off the idea of dropdowns - due to the huge amount of settings for each module. I have made a left side menu with buttons for each module: e.g. clock, calendar, weather, etc. Some current screenshot is attached.
    screen
    Screenshot from mobile phone:
    photo-2019-09-13-15-20-50

    Is there somethin on github that I can have a look at already?

    Not yet. Its a local development at this stage.

    @sdetweil said in config.js in JSON format:

    I have created modules using this capability.

    do you have your development available somewhere to look over?



  • This post is deleted!


  • @Serge remember, this is not MagicMirror…
    here is the mirror code
    https://github.com/evancohen/smart-mirror

    here is a module (plugin) for smart-mirror
    https://github.com/sdetweil/backgroundImage

    here is a sample plugin
    https://github.com/sdetweil/samplePlugin

    in the base mirror code, YOU have to edit the index.html to add
    the appropriate lines to enable your plugin



  • @sdetweil said in config.js in JSON format:

    @Serge remember, this is not MagicMirror…

    I have looked throught all the code. For simplicity I will call “SmartMirror” as SM and MagicMirror as MM further.

    1. config.schema.json files in SM contain plugins’ parameters and these files have JSON format. Example is a calendar config file smart-mirror/plugins/calendar/config.schema.json
    {
        "schema": {
            "calendar": {
                "type": "object",
                "title": "Calendar Settings",
                "properties": {
                    "icals": {
                        "type": "array",
                        "title": "iCal URLs",
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxResults": {
                        "type": "integer",
                        "title": "Max Number of Events for all iCals",
                        "default": 9
    
    1. config.js in MagicMirror is not made in JSON format so it is not easy to make changes there as compared to SM’s config.schema.json
    var config = {
    	address: "localhost", 
    	port: 8080,
    	ipWhitelist: [],
    	language: "en",
    	timeFormat: 24,
    	units: "metric",
    	modules: [
    		{
    			module: "newsfeed",
    			position: "bottom_bar",
    			config: {
    				feeds: [
    					{
    						title: "New York Times",
    						url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
    					}
    				],
    				showSourceTitle: true,
    				showPublishDate: true,
    				broadcastNewsFeeds: true,
    				broadcastNewsUpdates: true
    	}, },	], };
    

    Maybe I think wrong, please correct me if so.