BenRoe / MMM-FHEM

A module for the MagicMirror, to display data from FHEM devices.
MIT License
10 stars 14 forks source link

Readings are not updating. #8

Open DSteg opened 6 years ago

DSteg commented 6 years ago

Hi,

I have configured the module and it is showing the values correctly.

But the readings will not be updated.

Has someone an idea what could be wrong in my setting?

Thanks and best regards Dominik

BenRoe commented 6 years ago

Hi, unfortunately the module is not working with the current FHEM version. I don't have the time to update it.

DSteg commented 6 years ago

OK, do you know the problem, why it is not updating?

Or is there any workaround?

Maybe i can take look at it.

Thanks and regards

BenRoe commented 6 years ago

No clue what the problem is. Maybe the patch to the reading values changed. Would be great if you find the problem and open a PR.

DSteg commented 5 years ago

No idea why, but its works for two months now. I have not changed anything. Maybe a fhem update?! But I noticed, that it is only working until fhem will be restarted. Then you have to restart the Magic Mirror. It seems the connection will be invalid on a fhem restart and the module will not connect itself again.

Best regards

BenRoe commented 5 years ago

Thank you for the information. Sounds like a fundamental problem between FHEM and MM. I am not experienced enough to debug a MM Module connection to FHEM.

MadMax-git commented 5 years ago

First: thank you for the MM-FHEM!

Since you implemented a lot of things changed in fhem ;)

Something like the csrf_token has been implemented. Ether it is set to "none" via Attribute in FHEMWEB-instance (used for MagigMirror) or the code has to be extended using a fixed csrf_token (also to be set in FHEMWEB-Instance):

so the calls to fhem have to be extended with: &fwcsrf=fixed_token https://wiki.fhem.de/wiki/CsrfToken-HowTo

I changed following code in node_helper.js:

buildFhemUrl: function (config) { var deviceString = ''; config.devices.forEach(function(element, index, array) { deviceString += element.deviceName + ','; }); // start change if (config.https) { return 'https://' + config.host + ':' + config.port + '/fhem?cmd=jsonlist2%20NAME=' + deviceString + '&fwcsrf=' + config.csrf + '&XHR=1'; } else { return 'http://' + config.host + ':' + config.port + '/fhem?cmd=jsonlist2%20NAME=' + deviceString + '&fwcsrf=' + config.csrf + '&XHR=1'; } // end change },

An additional parameter: csrf: 'csrf_196525024154371',

And setting the attribute of the FHEMWEB instance used for MagicMirror:

attr WebMagicMirror csrfToken csrf_196525024154371

I encountered problems when I reboot/restart fhem -> the connection is lost and only reconnects when restarting MM.

I changed socketNotificationReceived in FHEM.js to the following:

socketNotificationReceived: function(notification, payload) { if (notification === 'DATARECEIVED') { // start change
if(payload === 'error') { this.scheduleUpdate(this.config.updateInterval); } // end change
this.devices = payload; // Log.log(payload); this.updateDom(2000); this.scheduleUpdate(this.config.updateInterval); }

Additionally I added the following in node_helper.js:

getFhemJson: function(config, callback) { request({ url: this.buildFhemUrl(config), json: true, }, function(error, response, body) { var self = this; if (!error && response.statusCode == 200) { // console.log(body); callback(body); } // start change
else { callback("error"); } // end change
});

AND

parseJson: function (json) { var self = this; var parsedJson = []; var resultsArray = json.Results;

// start change
if(json === 'error') { return "error"; } // end change
resultsArray.forEach(function(element, index, array) { var device = {}; // save value of property 'name' an array var readingsName = _.pluck(self.config.devices[index].deviceReadings, 'name');

  device.name = self.getDeviceName(element);
  device.values = self.getReadingsValue(readingsName, element);

  parsedJson.push(device);
});

return parsedJson;

},

(I hope I did not forget anything) Not a nice hack but it works. So the loop still keeps working...

Regards, Joachim

BenRoe commented 5 years ago

@MadMax-git thank you for the hints. Currently i have no FHEM running and not time to fix the problems. I add a information the the readme.md that this repository is no longer maintained. If someone is interested to maintain this project, please contact me and i will add you to this repository.