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

    Posts

    Recent Best Controversial
    • RE: MMM-Domoticz Cannot read property '0' of undefined

      Hi, I come back again because @sdetweil send me a MMM-Domoticz module. This module works with user and password of domoticz. So if you want see your domoticz devices on your MM you can use this code below.
      Just copy it on text editor and save it as domoticz.js in your MM module folder and in a domoticz folder

      /* global Module */
      
      /* Magic Mirror
       * Module: Domoticz
       *
       * By Mathias Arvidsson  & editing by sdetewell
       */
      
      Module.register("domoticz",{
      
      	defaults: {
      		units: 0,
      		updateInterval: 2000,
      		animationSpeed: 1000,
      		timeFormat: "HH:MM:ss",
      		lang: "en",
      
      		initialLoadDelay: 0,
      		retryDelay: 2500,
      
              apiBase: "http://xxx.xxx.x.xx",
      		apiUser: "xxxxx",
      		apiPw: "xxxxxxxxx",
      		sensors: [
      			{
      				idx: "1",
      				symbolon: "fa fa-user",
      				symboloff: "fa fa-user-o",
      				hiddenon: false,
      				hiddenoff: false,
      				customTitle: "",
      			},
      		],
      	},
      	keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
      		// sample data for parse testing
      	foo:'{ "result": [\
         {"Name":"test1", "Data":"foobar1","type":"something1"},\
      	  {"Name":"test2", "Data":"foobar2","type":"something2"},\
      		 {"Name":"test3", "Data":"foobar3","type":"something3"},\
      		  {"Name":"test4", "Data":"foobar4","type":"something4"}\
      ]}',
      
      	firstEvent: false,
      
        Base64_encode : function(input) {
          var output = "";
          var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
          var i = 0;
          input = this.Base64_utf8_encode(input);
          while (i < input.length) {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
              enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
              enc4 = 64;
            }
            output = output + this.keyStr.charAt(enc1) + this.keyStr.charAt(enc2) + this.keyStr.charAt(enc3) + this.keyStr.charAt(enc4);
          }
          return output;
        },
      
        Base64_decode : function(input) {
          var output = "";
          var chr1, chr2, chr3;
          var enc1, enc2, enc3, enc4;
          var i = 0;
          input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
          while (i < input.length) {
            enc1 = this.keyStr.indexOf(input.charAt(i++));
            enc2 = this.keyStr.indexOf(input.charAt(i++));
            enc3 = this.keyStr.indexOf(input.charAt(i++));
            enc4 = this.keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
              output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
              output = output + String.fromCharCode(chr3);
            }
          }
          output = this.Base64_utf8_decode(output);
          return output;
        },
      
        Base64_utf8_encode : function(string) {
          string = string.replace(/\r\n/g, "\n");
          var utftext = "";
          for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
              utftext += String.fromCharCode(c);
            } else if ((c > 127) && (c < 2048)) {
              utftext += String.fromCharCode((c >> 6) | 192);
              utftext += String.fromCharCode((c & 63) | 128);
            } else {
              utftext += String.fromCharCode((c >> 12) | 224);
              utftext += String.fromCharCode(((c >> 6) & 63) | 128);
              utftext += String.fromCharCode((c & 63) | 128);
            }
          }
          return utftext;
        },
      
        Base64_utf8_decode : function(utftext) {
          var string = "";
          var i = 0;
          var c = 0,
            c1 = 0,
            c2 = 0,
            c3 = 0;
          while (i < utftext.length) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
              string += String.fromCharCode(c);
              i++;
            } else if ((c > 191) && (c < 224)) {
              c2 = utftext.charCodeAt(i + 1);
              string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
              i += 2;
            } else {
              c2 = utftext.charCodeAt(i + 1);
              c3 = utftext.charCodeAt(i + 2);
              string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
              i += 3;
            }
          }
          return string;
        },
      
      
      
      	getStyles: function() {
      	    return ['font-awesome.css'];
      	},
      	// Define required scripts.
      	getScripts: function() {
      		return ["moment.js"];
      	},
      
      
      
      	// Define start sequence.
      	start: function() {
      		Log.info("Starting module: " + this.name);
      		// Set locale.
      		moment.locale(config.language);
      
      		this.loaded = false;
      		this.status1 = false;
      		this.title = "Loading...";
      		this.scheduleUpdate(this.config.updateInterval);//this.scheduleUpdate(this.config.initialLoadDelay);
      		this.sensors = [];
      		for (var c in this.config.sensors) {
      			var sensor = this.config.sensors[c];
      			var newSensor = {idx:sensor.idx, symbolon:sensor.symbolon, symboloff:sensor.symboloff, hiddenon:sensor.hiddenon, hiddenoff:sensor.hiddenoff, customTitle:sensor.customTitle, status:"", sname:"",type:""};
      			Log.log(sensor.idx);
      			this.sensors.push(newSensor);
      		}
      Log.log(JSON.stringify(this.sensors));
      	},
      
      
      
      	// Override dom generator.
      	getDom: function() {
      		var wrapper = document.createElement("div");
      
      		if (!this.loaded) {
      			wrapper.innerHTML = "Loading...";
      			wrapper.className = "dimmed light small";
      			return wrapper;
      		}
      		var tableWrap = document.createElement("table");
      		tableWrap.className = "small";
      
      		for (var c in this.sensors) {
      			var sensor = this.sensors[c];
      			if((sensor.status=="On" && sensor.hiddenon)||(sensor.status=="Off" && sensor.hiddenoff)) continue;
      			var sensorWrapper = document.createElement("tr");
      			sensorWrapper.className = "normal";
      
      			var symbolTD = document.createElement('td');
      			symbolTD.className = "symbol";
      			var symbol = document.createElement('i');
      			var symbolClass = sensor.symboloff
      			if(sensor.status=="On") symbolClass = sensor.symbolon
      			symbol.className = symbolClass;
      			symbolTD.appendChild(symbol);
      			sensorWrapper.appendChild(symbolTD);
      
      			var titleTD = document.createElement('td');
      			titleTD.className = "title bright";
      			if(sensor.status=="Off") titleTD.className = "title light";
      			titleTD.innerHTML = sensor.sname;
      			if(typeof sensor.customTitle !== 'undefined') titleTD.innerHTML = sensor.customTitle;
      			sensorWrapper.appendChild(titleTD);
      
      			var statusTD = document.createElement('td');
      			statusTD.className = "time light";
      			statusTD.innerHTML = sensor.status;
      			sensorWrapper.appendChild(statusTD);
      
      			tableWrap.appendChild(sensorWrapper);
      		}
      		wrapper.appendChild(tableWrap);
      		return wrapper;
      	},
      
      
      	updateDomo: function() {
      		var i = 0;
      		var self = this
      		let userid= this.Base64_encode(this.config.apiUser)
      		let password=this.Base64_encode(this.config.apiPw)
      		for (var sensor of this.sensors) {
      			
      			var url =  this.config.apiBase + ":" + this.config.apiPort + "/json.htm?username="+userid + "&password=" +password + "&type=devices&rid="  + sensor.idx;
      			let domoRequest = new XMLHttpRequest();
      			domoRequest.open("GET", url, true);
      			domoRequest.onreadystatechange = function() {
      				if (this.readyState === 4) {
      					// if the api response return code is 200 (ok)
      					if (this.status === 200) {
      						// if there was data returned
      						// example https://github.com/driverdan/node-XMLHttpRequest/blob/master/example/demo.js 
      						// uses this.responseText , not this.response
      						// this.response is an object
      						if(this.responseText && this.responseText.length>0){
      							// process it
      							self.processJson(JSON.parse(this.responseText));							
      							Log.log("Loaded data");
      						}
      						else {
      							 // oops, no data returned
      						   Log.error(self.name + ": no data returned.");
      						}
      					} else {
      						Log.error(self.name + ": Could not load data.");
      						Log.log("Did not load data");
      						// dummy call to verify parse works ok
      						// even where there are no devices
      						self.processJson(JSON.parse(self.foo));
      					}
      				}
      			};			
      			// watch out having multiple requests in progress at the same time. 
      			// onreadystatechange doesn't happen til LONG time after send..
      			// for loop starts another request immediately
      			domoRequest.send();			
      			i++;
      		}
      	},
      
      	processJson: function(data) {		
      		if (!data) {
      			// Did not receive usable new data.
      			// Maybe this needs a better check?
      			return;
      		}
      		Log.log("data="+data);
      		for (var c in this.sensors) {		
      		  // moved log entry here, as c is not set until start of for loop
      			// watch out if data does not contain "result":[] array
      			if( data.result !=='undefined' && typeof data.result ==='object' && data.result.length >0) {
      				Log.log("****Parsing data: " + c + " " + data.result[0].Name);		
      				var sensor = this.sensors[c];
      				if(sensor.idx == data.result[0].idx){
      					this.sensors[c].sname = data.result[0].Name;
      					this.sensors[c].status = data.result[0].Data;
      					this.sensors[c].type = data.result[0].Type;
      				}
      			}
      		}
      		
      		this.loaded = true;
      		this.updateDom(this.config.animationSpeed);
      	},
      
      	scheduleUpdate: function(delay) {
      		Log.log("Updating..");
      		var nextLoad = this.config.updateInterval;
      		if (typeof delay !== "undefined" && delay >= 0) {
      			nextLoad = delay;
      		}
      
      		//var self = this;
      		setInterval(() => {
      			this.updateDomo();
      		}, nextLoad);
      	}
      });
      

      After this in your config.js just add for exemple:

      		{
      			module: 'domoticz',
            			position: 'top_right',
            			header: 'Températures',
            				config: {
                  				apiBase: "http://xxx.xxx.x.xx",
                  				apiPort: "xx",
      					apiUser: "xxx",
      					apiPw: "xxxxxx",
                  			sensors: [
                        			{
      					idx: "183",
      					symbolon: "fa fa-thermometer-half",
      					symboloff: "fa fa-thermometer-half",
      					customTitle: "Cuisine",
      					},
                        			{
      					idx: "5",
      					symbolon: "fa fa-thermometer-half",
      					symboloff: "fa fa-thermometer-half",
      					customTitle: "Raspberry Domotique",
      					},					
      					]
      					}
         		},
      

      And it works
      Thanks @sdetweil for your help

      posted in Troubleshooting
      M
      MisterT
    • RE: MMM-GooglePhotos

      Hi @Sean, i have a question about MMM-GooglePhotos. It(s possible to display a lot of google photos locations ?
      that’s to say i want to display like a mosaic of six google photos on a same page.
      I try to add for exemple two MMM-google photos on my config.js with differents album paths but only one photo is shown.
      Have you an idea ?

      posted in Entertainment
      M
      MisterT
    • RE: MMM-Strava

      @ianperrin, i update your module and…tada it works :thumbs_up: great job
      MMM-Pages rotate and MMM Strava is visible
      Everything is good now

      I also try your other update about radial chart vizualisation and it’s great. I tested with year to date for bike and run and its’awesome. Just 2 remark:

      • In my opinion the radial gaphic it’s just a little too big and the graphic overlaps the other module.
      • I think we need informations about custom css in order to display colors about kilometers like for exemple:
        less 10 km for running in a month : red color
        from 10 to 30 km for running in a month: orange color
        over 30 km for running in a month : green color

      see you next time

      posted in Health
      M
      MisterT
    • RE: MMM-Strava

      @ianperrin i don’t know what i write and the meaning but if i modified these 2 lines (i don’t have the third line), i have MM rotation but undefined on MMM-Strava

         this.config.mode = this.config.mode.toLowerCase().mode;
        this.config.period = this.config.period.toLowerCase().period;
      

      The other error in wallberry module is a css error but i don’t think that it’s the problem of rotation because MMM-pages works with this error

      posted in Health
      M
      MisterT
    • RE: MMM-Strava

      @ianperrin thx for your reply, I’m the noob in .js but i tried to understand the problem and the report is about “toLowerCase”. In MMM-Strava.js, if i modify the three config lines witch contain the synthax “toLowercase”, the result on Magic Mirror is a rotation of MMM-Pages but a message “Undefined” for MMM-Strava

          this.config.mode = this.config.mode.toLowerCase();
          this.config.period = this.config.period.toLowerCase();
          this.config.chartType = this.config.chartType.toLowerCase();
      

      hope these light explanations can help you :face_screaming_in_fear:

      posted in Health
      M
      MisterT
    • RE: MMM-Strava

      hI @ianperrin
      I have another problem with MMM-Strava.
      I use it with MMM-Pages and MMM-Pages indicator. When i place the module in the config.js MMM-Pages settings, the Rotation of MMM-Pages doesn’t work and i have a error on Magic mirror when i press CTRL+SHIFT+i.
      See Thread below for mox explanations

      MMM-Pages no rotate

      Have you an idea?

      posted in Health
      M
      MisterT
    • RE: MMM-pages no rotate

      thanks @chassain-0 and @qu1que for your help.
      I found the gulty module. It’s MMM-Strava. When this module is in MMM-Pages Table, the rotation doesn’t work.
      So @ianperrin, do you have an idea why there is rotation problem with MMM-Strava since the autenthification has changed?

      posted in Troubleshooting
      M
      MisterT
    • RE: MMM-pages no rotate

      hi @chassain-0 i tried to put only clock in page 1 an MMM-freebox in page 2 or an other module but the result is the same. I have an error about “toLowerCase’ of undefined”.

      Can anybody help me please

      posted in Troubleshooting
      M
      MisterT
    • MMM-pages no rotate

      Hi everybody
      Todya i have a problem with MMM-pages Everythind wass alright until today.
      After add MMM-google photos (Idon’t know if this module the problem but i don’t think so) i modified my MMM-pages config.js and now MMM-pages doesn’t rotate.
      I have this error message when i press CTRL+SHIFT+i:

      (index):1 Refused to apply style from 'http://0.0.0.0:8080/modules/WallberryTheme/font-awesome5.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
      main.js:398 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
          at main.js:398
          at Array.filter (<anonymous>)
          at modulesByClass (main.js:397)
          at Array.exceptWithClass (main.js:380)
          at Class.animatePageChange (MMM-pages.js:152)
          at Class.updatePages (MMM-pages.js:136)
          at Class.notificationReceived (MMM-pages.js:78)
          at sendNotification (main.js:95)
          at Object.sendNotification (main.js:502)
          at Class.sendNotification (module.js:368)
      main.js:398 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
          at main.js:398
          at Array.filter (<anonymous>)
          at modulesByClass (main.js:397)
          at Array.exceptWithClass (main.js:380)
          at Class.animatePageChange (MMM-pages.js:152)
          at Class.updatePages (MMM-pages.js:136)
          at Class.notificationReceived (MMM-pages.js:85)
          at sendNotification (main.js:95)
          at Object.sendNotification (main.js:502)
          at Class.sendNotification (module.js:368)
      (index):1 Refused to apply style from 'http://0.0.0.0:8080/modules/WallberryTheme/font-awesome5.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
      main.js:398 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
          at main.js:398
          at Array.filter (<anonymous>)
          at modulesByClass (main.js:397)
          at Array.exceptWithClass (main.js:380)
          at Class.animatePageChange (MMM-pages.js:152)
          at Class.updatePages (MMM-pages.js:136)
          at self.timer.setInterval (MMM-pages.js:189)
      (anonymous) @ main.js:398
      modulesByClass @ main.js:397
      exceptWithClass @ main.js:380
      animatePageChange @ MMM-pages.js:152
      updatePages @ MMM-pages.js:136
      self.timer.setInterval @ MMM-pages.js:189
      main.js:398 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
          at main.js:398
          at Array.filter (<anonymous>)
          at modulesByClass (main.js:397)
          at Array.exceptWithClass (main.js:380)
          at Class.animatePageChange (MMM-pages.js:152)
          at Class.updatePages (MMM-pages.js:136)
          at self.timer.setInterval (MMM-pages.js:189)
      (anonymous) @ main.js:398
      modulesByClass @ main.js:397
      exceptWithClass @ main.js:380
      animatePageChange @ MMM-pages.js:152
      updatePages @ MMM-pages.js:136
      self.timer.setInterval @ MMM-pages.js:189
      

      The problem is in main magic mirror js and in MMM-pages js
      I’m noob in js and i don’t knwow this error

      i tried to delete MMM-pages an reinstall it but this is the same thing

      At every end of rotation time, MMM-Pages indicaator change the indicator but the page doesn’t want to rotate and i have the error message

      See below my MMM-pages config.js

      {
      	module: 'MMM-pages',
      	config: {
      	modules:
      [[ "WallberryTheme", "WallberryTheme/WB-clock", "WallberryTheme/WB-weather"],
      [ "clock", "weatherforecast", "newsfeed", "MMM-GoogleMapsTraffic", "MMM-Traffic", "MMM-Scrobbler", "MMM-News"],
      [ "clock", "calendar", "MMM-Globe", "MMM-MovieListings", "MMM-soccer", "MMM-AQI", "MMM-Strava"],
      [ "clock", "MMM-FreeBox-Monitor", "MMM-Spotify", "fabio/domoticz", 'currentweather'],
      [ "MMM-GooglePhotos" ]],
      fixed: ["MMM-GroveGestures", "MMM-AssistantMk2", "MMM-Hotword", "alert", "updatenotification", "MMM-Screencast", "MMM-page-indicator"],
      				
      animationTime:1000,
      rotationTime: 0.5*60*1000,
      rotationDelay: 15000,
      }
          },
      
      {
             module: 'MMM-page-indicator',
              position: 'bottom_bar',
              config: {
                  		pages:5 ,
             			}
      	},
      

      Have you an idea?

      posted in Troubleshooting
      M
      MisterT
    • RE: MMM-Strava configuration

      Solved see module in health section

      posted in Troubleshooting
      M
      MisterT
    • 1 / 1