danielolson13 / wink-mqtt

Enable local-control of a rooted Wink Hub with MQTT
MIT License
31 stars 9 forks source link

Update Status #4

Closed Mdleal closed 8 years ago

Mdleal commented 8 years ago

Is there a way to send a message to get a status of all devices? Maybe send 'home/update' to the wink.

danielolson13 commented 8 years ago

Sure, I could implement that but I'd rather fix it so no "update all" needs to be called.

Ideally the tailing of the log file should read what device is changing and if it's a binary attribute just send an update, skipping the database check. Right now every time a state change is logged it does a check of the database and updates all values. If multiple states are changed at or around the same time, only one database check is done and the other checks that should have been done are discarded for the sake of memory.

Is your issue with not all devices getting updated related multiple states changing at the same time?

On Thu, Feb 25, 2016 at 5:18 PM Mdleal notifications@github.com wrote:

Is there a way to send a message to get a status of all devices? Maybe send 'home/update' to the wink.

— Reply to this email directly or view it on GitHub https://github.com/danielolson13/wink-mqtt/issues/4.

Mdleal commented 8 years ago

If I reboot openhab I would like to send a request to update the device's status when it starts back up. I think I have it figured out. What function runs when the node.js starts?

danielolson13 commented 8 years ago

When OpenHAB subscribes after a restart it will receive the retained message/statuses from your mqtt broker. If the mqtt broker restarts it may not maintain the retained messages, unless you have it configured to maintain a database. Is your mqtt broker restarting too?

In wink-mqtt.js it uses the checkDatabase() function to compare values stored locally in a deviceStatus variable and compares to the results from the database. To force updates on devices you could subscribe to "home/update" and then have an on message function like...

danielolson13 commented 8 years ago
    function updateAll(){
        deviceStatus = {};
        checkDatabase();
    }
Mdleal commented 8 years ago

My broker is on the same VM as my Openhab server. That could be the problem. Thank you for the code. I had the checkDatabase but I was missing the deviceStatus part.