Bon, comme pour tout le reste , le fichier domoticz.js à placer au bon endroit. (fais moi signe si tu galères, je te guiderai un peu plus précisément!)
Rien a changer à part l'adresse IP et le port
Code : Tout sélectionner
/* global Module */
/* Magic Mirror
* Module: Domoticz
*
* By Mathias Arvidsson
*/
Module.register("domoticz",{
defaults: {
units: config.units,
updateInterval: 50,
animationSpeed: 1000,
timeFormat: config.timeFormat,
lang: config.language,
initialLoadDelay: 0,
retryDelay: 2500,
apiBase: "http://192.168.0.33", // IP domoticz
apiPort: "8080", // 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:""};
console.log(sensor.idx);
this.sensors.push(newSensor);
}
console.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" && 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;
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&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));
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];
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) {
console.log("Updating..");
var nextLoad = this.config.updateInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay;
}
var self = this;
setInterval(function() {
self.updateDomo();
}, 50000);
}
});
Dans le config.js, ajouter les lignes ci-dessous en modifiant une fois encore l'IP et le Port:
Code : Tout sélectionner
{
module: 'domoticz',
position: 'top_left',
header: 'Domoticz',
config: {
apiBase: "http://192.168.0.33",
apiPort: "8080",
sensors: [
{
idx: "966",
symbolon: "fa fa-thermometer-half",
symboloff: "fa fa-thermometer-half",
customTitle: "Chambre 1",
},
{
idx: "3887",
symbolon: "fa fa-thermometer-half",
symboloff: "fa fa-thermometer-half",
customTitle: "Chambre 2",
},
{
idx: "3886",
symbolon: "fa fa-thermometer-half",
symboloff: "fa fa-thermometer-half",
customTitle: "Cuisine",
},
{
idx: "520",
symbol: "fa fa-thermometer-half",
symboloff: "fa fa-thermometer-half",
customTitle: "Salon SaM",
},
{
idx: "3880",
symbol: "fa fa-thermometer-half",
symboloff: "fa fa-thermometer-half",
customTitle: "SdB RdC",
},
{
idx: "272",
symbol: "fa fa-bolt",
symboloff: "fa fa-bolt",
customTitle: "Consommation cumulée Maison",
unit : "kWh",
},
{
idx: "473",
symbolon: "fa fa-toggle-on",
symboloff: "fa fa-toggle-off",
customTitle: "VMC SdB RdC",
},
{
idx: "382",
symbolon: "fa fa-toggle-on",
symboloff: "fa fa-toggle-off",
customTitle: "Téléphone",
},
{
idx: "383",
symbolon: "fa fa-toggle-on",
symboloff: "fa fa-toggle-off",
customTitle: "Sonnette",
},
{
idx: "3913",
symbolon: "fa fa-exclamation-circle",
symboloff: "fa fa-thumbs-up",
customTitle: "Portail 1",
},
{
idx: "3910",
symbolon: "fa fa-exclamation-circle",
symboloff: "fa fa-thumbs-up",
customTitle: "Portail 2",
},
]
}
},
Voilà, Chez moi tout fonctionne pour peu que le User + Password ne soit pas renseigné.
J'ai fait d'autres essais avec un module modifié, mais je n'y ai pas accès, le Raspberry est "out" ce soir.
En espérant avoir été utile !
Manu