<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined]]></title><description><![CDATA[<p dir="auto">Hi everybody<br />
I update my magic mirror from 2.6 to 2.8 and also npm to the latest version and now i have error on console (ctrl+ maj+i) with MMM-Domoticz:</p>
<p dir="auto">domoticz.js:150 Uncaught TypeError: Cannot read property ‘0’ of undefined<br />
at Class.processJson (domoticz.js:150)<br />
at XMLHttpRequest.domoRequest.onreadystatechange (domoticz.js:128)</p>
<p dir="auto">you see below the domoticz.js short program:</p>
<pre><code>line 115: updateDomo: function() {
		var i = 0;
		for (var c in this.sensors) {
			//console.log("this is c: " + c);
			var sensor = this.sensors[c];
			var url = this.config.apiBase + ":" + this.config.apiPort + "/json.htm?type=devices&amp;rid="  + sensor.idx;
			var self = this;

			var domoRequest = new XMLHttpRequest();
			domoRequest.open("GET", url, true);
			domoRequest.onreadystatechange = function() {
				if (this.readyState === 4) {
					if (this.status === 200) {
						line 128: self.processJson(JSON.parse(this.response));
						//console.log("Loaded data");
					} else {
						Log.error(self.name + ": Could not load data.");
						//console.log("Did not load data");
					}
				}
			};
			domoRequest.send();
			i++;
		}
	},

	processJson: function(data) {
		//console.log("****Parsing data: " + c + " " + data.result[0].Name);
		if (!data) {
			// Did not receive usable new data.
			// Maybe this needs a better check?
			return;
		}
		for (var c in this.sensors) {
			var sensor = this.sensors[c];
			line 150: 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;
			}
		}
</code></pre>
<p dir="auto">and also i have also a problem with console.log (to mm2.6 also) the error message is:</p>
<p dir="auto">console.log is not a function.</p>
<p dir="auto">I post this because i’m noob in js script. My intenet searching for this problem is a failure.</p>
<p dir="auto">Can anyboby help me please?<br />
thanls for next answers</p>
]]></description><link>https://forum.magicmirror.builders/topic/11123/mmm-domoticz-cannot-read-property-0-of-undefined</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 04:41:27 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/11123.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 Sep 2019 12:59:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Mon, 21 Feb 2022 15:39:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: mistert">@<bdi>mistert</bdi></a> electron is enforcing more things than before…</p>
<p dir="auto">see this post for a possible workaround</p>
<p dir="auto"><a href="https://forum.magicmirror.builders/topic/16384/node-helper-access-control-allow-origin/2?_=1645457720236">https://forum.magicmirror.builders/topic/16384/node-helper-access-control-allow-origin/2?_=1645457720236</a></p>
]]></description><link>https://forum.magicmirror.builders/post/99835</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/99835</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 21 Feb 2022 15:39:01 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Mon, 21 Feb 2022 13:50:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi, everybody<br />
I used this old thread because i have a other problem with this module. I update my magic mirror to 2.8 and now this module doesn’t work properly. the error is:</p>
<pre><code>Domoticz.js:260 GET http://1xx.1xx1.3x:xxxx/json.htm?username=RmFiaWVu&amp;password=ZmwwNjA2ODVEb21vdGljeg==&amp;type=devices&amp;rid=334 net::ERR_FAILED
updateDomo @ domoticz.js:260
(anonymous) @ domoticz.js:299
0.0.0.0/:1 Access to XMLHttpRequest at 'http://1xx.1xx1.3x:xxxx/json.htm?username=RmFiaWVu&amp;password=ZmwwNjA2ODVEb21vdGljeg==&amp;type=devices&amp;rid=336' from origin 'http://0.0.0.0:8080' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space `private`.
domoticz.js:249 domoticz: Could not load data.
domoRequest.onreadystatechange @ domoticz.js:249
XMLHttpRequest.send (async)
updateDomo @ domoticz.js:260
(anonymous) @ domoticz.js:299
domoticz.js:250 Did not load data
domoticz.js:271 data=[object Object]
domoticz.js:276 ****Parsing data: 0 test1
domoticz.js:276 ****Parsing data: 1 test1
domoticz.js:276 ****Parsing data: 2 test1
domoticz.js:276 ****Parsing data: 3 test1
domoticz.js:276 ****Parsing data: 4 test1
domoticz.js:276 ****Parsing data: 5 test1
domoticz.js:276 ****Parsing data: 6 test1
domoticz.js:260 GET http://1xx.1xx1.3x:xxxx/json.htm?username=RmFiaWVu&amp;password=ZmwwNjA2ODVEb21vdGljeg==&amp;type=devices&amp;rid=336 net::ERR_FAILED
</code></pre>
<p dir="auto">I think the json request doesn’t match with the good domoticz request</p>
<p dir="auto"><a href="http://1xx.1xx1.3x" target="_blank" rel="noopener noreferrer nofollow ugc">http://1xx.1xx1.3x</a>:xxxx/json.htm?username=RmFiaWVu&amp;password=ZmwwNjA2ODVEb21vdGljeg==&amp;type=devices&amp;rid=336</p>
<p dir="auto">ip and port are good but all these after are bad.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> is the most contributor of this code. have you an idea?<br />
i use the same code that the code is above this post</p>
<p dir="auto">thanks for your help</p>
]]></description><link>https://forum.magicmirror.builders/post/99834</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/99834</guid><dc:creator><![CDATA[MisterT]]></dc:creator><pubDate>Mon, 21 Feb 2022 13:50:08 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Tue, 07 Jan 2020 18:14:13 GMT]]></title><description><![CDATA[<p dir="auto">Hi, I come back again because <a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> 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.<br />
Just copy it on text editor and save it as domoticz.js in your MM module folder and in a domoticz folder</p>
<pre><code>/* global Module */

/* Magic Mirror
 * Module: Domoticz
 *
 * By Mathias Arvidsson  &amp; 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 &lt; input.length) {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
      enc1 = chr1 &gt;&gt; 2;
      enc2 = ((chr1 &amp; 3) &lt;&lt; 4) | (chr2 &gt;&gt; 4);
      enc3 = ((chr2 &amp; 15) &lt;&lt; 2) | (chr3 &gt;&gt; 6);
      enc4 = chr3 &amp; 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 &lt; 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 &lt;&lt; 2) | (enc2 &gt;&gt; 4);
      chr2 = ((enc2 &amp; 15) &lt;&lt; 4) | (enc3 &gt;&gt; 2);
      chr3 = ((enc3 &amp; 3) &lt;&lt; 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 &lt; string.length; n++) {
      var c = string.charCodeAt(n);
      if (c &lt; 128) {
        utftext += String.fromCharCode(c);
      } else if ((c &gt; 127) &amp;&amp; (c &lt; 2048)) {
        utftext += String.fromCharCode((c &gt;&gt; 6) | 192);
        utftext += String.fromCharCode((c &amp; 63) | 128);
      } else {
        utftext += String.fromCharCode((c &gt;&gt; 12) | 224);
        utftext += String.fromCharCode(((c &gt;&gt; 6) &amp; 63) | 128);
        utftext += String.fromCharCode((c &amp; 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 &lt; utftext.length) {
      c = utftext.charCodeAt(i);
      if (c &lt; 128) {
        string += String.fromCharCode(c);
        i++;
      } else if ((c &gt; 191) &amp;&amp; (c &lt; 224)) {
        c2 = utftext.charCodeAt(i + 1);
        string += String.fromCharCode(((c &amp; 31) &lt;&lt; 6) | (c2 &amp; 63));
        i += 2;
      } else {
        c2 = utftext.charCodeAt(i + 1);
        c3 = utftext.charCodeAt(i + 2);
        string += String.fromCharCode(((c &amp; 15) &lt;&lt; 12) | ((c2 &amp; 63) &lt;&lt; 6) | (c3 &amp; 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" &amp;&amp; sensor.hiddenon)||(sensor.status=="Off" &amp;&amp; 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 + "&amp;password=" +password + "&amp;type=devices&amp;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 &amp;&amp; this.responseText.length&gt;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' &amp;&amp; typeof data.result ==='object' &amp;&amp; data.result.length &gt;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" &amp;&amp; delay &gt;= 0) {
			nextLoad = delay;
		}

		//var self = this;
		setInterval(() =&gt; {
			this.updateDomo();
		}, nextLoad);
	}
});
</code></pre>
<p dir="auto">After this in your config.js just add for exemple:</p>
<pre><code>		{
			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",
					},					
					]
					}
   		},
</code></pre>
<p dir="auto">And it works<br />
Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> for your help</p>
]]></description><link>https://forum.magicmirror.builders/post/67535</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/67535</guid><dc:creator><![CDATA[MisterT]]></dc:creator><pubDate>Tue, 07 Jan 2020 18:14:13 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Thu, 12 Sep 2019 03:30:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> sent response via email</p>
]]></description><link>https://forum.magicmirror.builders/post/61181</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61181</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 12 Sep 2019 03:30:19 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Wed, 11 Sep 2019 19:44:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> Hello again, I noticed that have changed the row “setInterval(function() {” to<br />
“setTimeout(function() {”</p>
]]></description><link>https://forum.magicmirror.builders/post/61178</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61178</guid><dc:creator><![CDATA[Nilnik]]></dc:creator><pubDate>Wed, 11 Sep 2019 19:44:29 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Wed, 11 Sep 2019 18:15:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> i send you a personal mail with my domoticz module and config.js.<br />
Thanks for your help</p>
]]></description><link>https://forum.magicmirror.builders/post/61175</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61175</guid><dc:creator><![CDATA[MisterT]]></dc:creator><pubDate>Wed, 11 Sep 2019 18:15:29 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Tue, 10 Sep 2019 20:13:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> I have the same module domoticz (M.Arvidsson) and it works fine for me. I can seei n your domoticz.js that ievery row with log.log … , I have console.log. Maybe thats the problem.</p>
]]></description><link>https://forum.magicmirror.builders/post/61158</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61158</guid><dc:creator><![CDATA[Nilnik]]></dc:creator><pubDate>Tue, 10 Sep 2019 20:13:45 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Tue, 10 Sep 2019 17:50:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> there is also a newer module  (2 months) same name  from another user</p>
<p dir="auto"><a href="https://github.com/SpoturDeal/MMM-Domoticz" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/SpoturDeal/MMM-Domoticz</a></p>
<p dir="auto">this module (M-Arvidsson) hasn’t been updated in 3 yrs</p>
]]></description><link>https://forum.magicmirror.builders/post/61151</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61151</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 10 Sep 2019 17:50:47 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Tue, 10 Sep 2019 17:49:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> could you email the module config (from config.js) to my email same userid as here on gmail…</p>
]]></description><link>https://forum.magicmirror.builders/post/61150</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61150</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 10 Sep 2019 17:49:25 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Tue, 10 Sep 2019 17:04:26 GMT]]></title><description><![CDATA[<p dir="auto">hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> , sorry for this late answer, i’m very busy at this moment</p>
<p dir="auto">I applied your programe line and now, in the console i have:</p>
<p dir="auto">:8080/modules/fabio/domoticz//domoticz.js:142 Uncaught TypeError: Cannot read property ‘0’ of undefined<br />
at Class.processJson (:8080/modules/fabio/domoticz//domoticz.js:142)<br />
at XMLHttpRequest.domoRequest.onreadystatechange (:8080/modules/fabio/domoticz//domoticz.js:128)</p>
<p dir="auto">and this:</p>
<p dir="auto">domoticz.js:142 Uncaught TypeError: Cannot read property ‘0’ of undefined<br />
at Class.processJson (domoticz.js:142)<br />
at XMLHttpRequest.domoRequest.onreadystatechange (domoticz.js:128)<br />
processJson @ domoticz.js:142<br />
domoRequest.onreadystatechange @ domoticz.js:128<br />
XMLHttpRequest.send (async)<br />
updateDomo @ domoticz.js:136<br />
(anonymous) @ domoticz.js:170</p>
<p dir="auto">and the js script below</p>
<pre><code>/* global Module */

/* Magic Mirror
 * Module: Domoticz
 *
 * By Mathias Arvidsson
 */

Module.register("domoticz",{

	defaults: {
		units: config.units,
		updateInterval: 50,
		animationSpeed: 0,
		timeFormat: config.timeFormat,
		lang: config.language,

		initialLoadDelay: 0,
		retryDelay: 2500,

		apiBase: "http://1xx.1xx.x.xx", // IP domoticz 
		apiPort: "xxxx",				 // Port
		sensors: [
			{
				idx: "1",
				symbolon: "fa fa-user",
				symboloff: "fa fa-user-o",
				hiddenon: false,
				hiddenoff: false,
				customTitle: "",
			},
		],
	},

	firstEvent: false,
	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.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(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" &amp;&amp; sensor.hiddenon)||(sensor.status=="Off" &amp;&amp; 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;
		for (var c in this.sensors) {
			Log.log("this is c: " + c);
			var sensor = this.sensors[c];
			var url = this.config.apiBase + ":" + this.config.apiPort + "/json.htm?type=devices&amp;rid="  + sensor.idx;
			var self = this;

			var domoRequest = new XMLHttpRequest();
			domoRequest.open("GET", url, true);
			domoRequest.onreadystatechange = function() {
				if (this.readyState === 4) {
					if (this.status === 200) {
						self.processJson(JSON.parse(this.response));
						Log.log("Loaded data");
					} else {
						Log.error(self.name + ": Could not load data. request status="+this.status);
						Log.log("Did not load data");
					}
				}
			};
			domoRequest.send();
			i++;
		}
	},

	processJson: function(data) {
		Log.log("****Parsing data: " + c + " " + data.result[0].Name);
		if (!data) {
			// Did not receive usable new data.
			// Maybe this needs a better check?
			return;
		}
		for (var c in this.sensors) {
			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" &amp;&amp; delay &gt;= 0) {
			nextLoad = delay;
		}

		var self = this;
		setInterval(function() {
			self.updateDomo();
		}, 500 );
	}
});
</code></pre>
<p dir="auto">for your information, the module seems to work but i have this error.</p>
<p dir="auto">Have you a solution?<br />
thanks a lot</p>
]]></description><link>https://forum.magicmirror.builders/post/61149</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61149</guid><dc:creator><![CDATA[MisterT]]></dc:creator><pubDate>Tue, 10 Sep 2019 17:04:26 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Mon, 09 Sep 2019 01:51:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> change this line</p>
<pre><code>Log.error(self.name + ": Could not load data.");
</code></pre>
<p dir="auto">to this</p>
<pre><code>Log.error(self.name + ": Could not load data. request status="+this.status);
</code></pre>
<p dir="auto">this will show the error return code on the api url request for the data</p>
]]></description><link>https://forum.magicmirror.builders/post/61084</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61084</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 09 Sep 2019 01:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Sun, 08 Sep 2019 14:02:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> said in <a href="/post/61021">MMM-Domoticz Cannot read property '0' of undefined</a>:</p>
<blockquote>
<p dir="auto">this is not set correctly if called in the domoRequest.onreadystatechange = function() {}<br />
u should be using self… ‘this’ is context sensitive, means ‘inside this function’</p>
</blockquote>
<p dir="auto">hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a>, i replace conole.log by Log.log and now i have error in the console</p>
<p dir="auto">Could not load data.<br />
refered to line 131.</p>
<p dir="auto">Sorry but i don’t unerstand your last post about this and self. Can you show me the good syntax or do you need the entire program?</p>
<p dir="auto">thanks for your help</p>
]]></description><link>https://forum.magicmirror.builders/post/61073</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61073</guid><dc:creator><![CDATA[MisterT]]></dc:creator><pubDate>Sun, 08 Sep 2019 14:02:01 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Sat, 07 Sep 2019 13:11:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> said in <a href="/post/61016">MMM-Domoticz Cannot read property '0' of undefined</a>:</p>
<blockquote>
<pre><code>  	var sensor = this.sensors[c];
</code></pre>
</blockquote>
<p dir="auto">this is not set correctly if called in the domoRequest.onreadystatechange = function() {}<br />
u should be using self… ‘this’ is context sensitive, means ‘inside this function’</p>
]]></description><link>https://forum.magicmirror.builders/post/61021</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61021</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 07 Sep 2019 13:11:38 GMT</pubDate></item><item><title><![CDATA[Reply to MMM-Domoticz Cannot read property &#x27;0&#x27; of undefined on Sat, 07 Sep 2019 13:08:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mistert" aria-label="Profile: MisterT">@<bdi>MisterT</bdi></a> said in <a href="/post/61016">MMM-Domoticz Cannot read property '0' of undefined</a>:</p>
<blockquote>
<p dir="auto">console.log is not a function.</p>
</blockquote>
<p dir="auto">in the module.js, logging is done with the Log function, not console…</p>
<p dir="auto">so, change any console.log to Log.log</p>
]]></description><link>https://forum.magicmirror.builders/post/61020</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/61020</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 07 Sep 2019 13:08:14 GMT</pubDate></item></channel></rss>