maximvelichko / pyvera

A python library to control devices via the Vera hub
GNU General Public License v2.0
26 stars 31 forks source link

Do a better job at handling Comms Failure (esp in Home Assistant) #147

Open pavoni opened 3 years ago

pavoni commented 3 years ago

To continue the discussion started here: https://github.com/pavoni/pyvera/pull/146#issuecomment-770235776

It would be good to make Vera devices handle comm failure updates in HA.

@tgrusendorf comments on some of the issues here: https://github.com/pavoni/pyvera/pull/146#issuecomment-770230599

After a comm failure returns to normal, the Vera subscription does not always report the state returning to -1, so often the last subscription update I get for the device shows state 1 with comm failure = 0. It looks like you've encountered a similar issue with locks not returning state to -1, so I'm using your lock workaround for all devices at the moment. Requesting a complete update from Vera does show that the state has returned to -1. I'm planning to add another issue for this, it probably needs some discussion.

If this is an issue with vera not sending subscription updates - then we could force state refreshes when devices are asked for their state and they are in comms failure.

I'm pretty sure @vangorra modified the HA integration so that the HA devices poll as well as responding to subscription updates (HA objects poll by default unless you tell them not to - and he just removed my code that turned this off).

The catch is when HA polls the pyvera device - it returns cached values (unless you pass refresh=true to get the status from the real device). But this shouldn't be hard,

I think HA has the infrastructure to do this pretty easily.

Once a device is in comm failure, Vera doesn't necessarily continue trying it. For my flood sensor it does, so it will return to normal on its own. For my dimmers it does not, so I have to ask Vera to poll the device. I'm considering adding a 'Poll Device' service to the Vera integration so that I can trigger a poll from HA. Would you consider adding periodic polling of devices with comm failure to pyvera?

Again I think the easiest thing would be to add a force_vera_to_poll_device method to VeraDevice that could be called on a HA poll

I think @vangorra is busy with other things - but he might have a few moments to comment.

tgrusendorf commented 3 years ago

Issue part 1 - Vera not sending subscription updates - I like the idea of forcing a state refresh. When the device comes out of comm failure, it looks like we always get a subscription update indicating that CommFailure has changed to 0 but not necessarily the state change back to -1 (sometimes we do and sometimes we don't). This transition of CommFailure from 1 to 0 is what I would be inclined to use to trigger a state refresh.

Issue part 2 - Forcing Vera to poll the device - I agree with adding the method, and probably calling it on a HA poll is the right time to do it. For reference, the URL I have been using to force Vera to poll the device is: http://[vera IP]:3480/data_request?id=action&DeviceNum=[device id]&serviceId=urn:micasaverde-com:serviceId:HaDevice1&action=Poll. So far all of the Vera devices I have appear to support this action. If we want to first confirm that the device supports the 'Poll' action, we can look at the response to http://[vera IP]:3480/data_request?id=lu_invoke&DeviceNum=[device id] to confirm.

pavoni commented 3 years ago

BTW I should perhaps add that, if you can, it would be best to get your zwave network to be more reliable.

Perhaps add a couple of extra mains power zwave switches to fill the network holes on the way to your unreliable devices.

I've just done this - and it has helped a lot with the one device I find is unreliable.

Doesn't take away from the goal of making pyvera handle this this better of course.

pavoni commented 3 years ago

You can see what I did in HA here https://github.com/home-assistant/core/pull/46064

How often were you triggering zwave polls?

tgrusendorf commented 3 years ago

Thanks - I'm looking forward to trying it out, but won't be able to for another week or so due to work.

I was just triggering zwave polls manually during my testing. I don't think it's something we need to do too frequently with a device in comm failure. Vera retries several times before it flags a comm failure. Maybe start with attempting to poll a device in comm failure every 60s, with a backoff strategy to eventually only retry every 5 minutes?

My Zwave network is actually quite reliable - the only comm failures I'm having are induced by myself for testing. Coming from an industrial automation background I'm paranoid about unhandled / unreported failures (e.g. flood sensors that you don't realize aren't working until it's too late - had that happen twice with a cheap D-Link flood sensor).

pavoni commented 3 years ago

Do the flood sensors also report temperature? Might give you a way of alerting if they stop reporting.

tgrusendorf commented 3 years ago

The one I'm using does.

https://www.aartech.ca/hs-fs100-w/homeseer-zwave-flex-sensor-temperature-and-perimeter-water-sensor.html

Just using comm failure on the binary sensor indicating water works just fine. The flood sensor actually recovers from a comm failure on its own eventually (probably because it publishes updates without polling). My dimmers, switches and plug modules don't recover without a manual poll.

tgrusendorf commented 3 years ago

I had the chance to do some testing today with the latest updates. Setting 'should_poll' to True on a comm failure in order to trigger polling all parameters from Vera doesn't appear to be helping issue #1.

When I have a comm failure and should_poll becomes True, I don't see the update method being called for that device. I added logging to the should_poll property to indicate every time it is called, and it looks like it is only being checked at startup or when a entity service is called (e.g. turn_on or turn_off).

For now I've just set should_poll to True so that my devices are updated both by polling and subscription, and that has temporarily resolved issue #1.

pavoni commented 3 years ago

How are you testing? should_poll is called by the home assistant poll code. I don’t think this HA integration change has made it into a home assistant release yet.

tgrusendorf commented 3 years ago

I'm running the Vera component as a custom component for testing. I grabbed the current files with your merged PR from the repo (here) and replaced my custom component with them (and then added some more logging).

I'm running Home Assistant 2021.2.3.

Attached is my log file. Below are the relevant times: 18:39 disconnected switch 18:39:28 called turn_on service 18:50 reconnected switch 18:51 polled device via Vera UI

I added logging to the VeraDevice update and should_poll methods, so you will see events like this in the log when they are called:

VERA update method called for device {}
VERA should_poll property method called for device {}.  Returning {}

home-assistant.log

pavoni commented 3 years ago

Do you know if you have the latest version of the pyvera library installed?

pavoni commented 3 years ago

Just to check I wasn't dreaming, I added some logging to my dev setup. Apart from the logs this is running the current HA dev branch.

Here are the changes to VeraDevice :-


     def update(self):
         """Force a refresh from the device if the device is unavailable."""
+        _LOGGER.info("%s: update called (refresh=%s)", self._name, not self.available)
         if not self.available:
             self.vera_device.refresh()

@@ -245,6 +246,8 @@ class VeraDevice(Generic[DeviceType], Entity):
     @property
     def should_poll(self) -> bool:
         """Get polling requirement from vera device."""
+        _LOGGER.info("%s: should_poll called (should_poll=%s)", self._name, self.vera_device.should_poll)
+
         return self.vera_device.should_poll

     @property
(END)

And here are the logs

2021-02-22 11:39:06 DEBUG (SyncWorker_1) [pyvera] get_alerts() requesting payload {'LoadTime': 1613710707, 'DataVersion': 710739047, 'id': 'status'}
2021-02-22 11:39:06 DEBUG (SyncWorker_1) [pyvera] Poll returned
2021-02-22 11:39:06 DEBUG (SyncWorker_1) [pyvera] Event: Study uplighters, state -1, alerts 0, {"altid": "2", "id": "3", "subcategory": "0", "room": "4", "parent": "1", "configured": "1", "commFailure": "0", "kwh": "26.2100", "watts": "0.0", "status": "0", "level": "0", "state": "-1", "comment": ""}
2021-02-22 11:39:06 INFO (SyncWorker_3) [homeassistant.components.vera] Study uplighters: update called (refresh=False)
2021-02-22 11:39:07 DEBUG (SyncWorker_2) [pyvera] Polling for Vera changes
2021-02-22 11:39:07 DEBUG (SyncWorker_2) [pyvera] get_changed_devices() requesting payload {'timeout': 30, 'minimumdelay': 200, 'id': 'lu_sdata', 'loadtime': 1613710707, 'dataversion': 710739048}
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Flood Sensor (temperature): should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Skylight Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] temperature upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] light: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] humidity upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] 97 Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 1: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Skylight Ctrl Temp: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Gate Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 2: should_poll called (should_poll=False)
2021-02-22 11:39:07 INFO (MainThread) [homeassistant.components.vera] Aeon Z-Stick: should_poll called (should_poll=True)
2021-02-22 11:39:07 INFO (SyncWorker_5) [homeassistant.components.vera] Aeon Z-Stick: update called (refresh=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Flood Sensor: should_poll called (should_poll=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight position: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Multisensor 6 in 1: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 3: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor): should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 4: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 5: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 6: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 7: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GateSmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (SyncWorker_1) [homeassistant.components.vera] Flood Sensor: update called (refresh=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Master Entry: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Flood Sensor: should_poll called (should_poll=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight position: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Multisensor 6 in 1: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Repeater switch: should_poll called (should_poll=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] SmartImplant IN2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 3: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Rain Sensor Switch: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Rain Sensor Switch 2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor): should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 4: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight Open: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight Close: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 5: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Mix 3: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Mix 2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Coffee: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Gate Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GateSmartImplant IN2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 6: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GET_LANG(generic_sensor,sensor) 7: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Gate Sensor Switch: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Gate Toggle: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] GateSmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Preamp: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Appliance Module 9: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Appliance Module 10: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (SyncWorker_3) [homeassistant.components.vera] Flood Sensor: update called (refresh=True)
2021-02-22 11:39:12 INFO (SyncWorker_4) [homeassistant.components.vera] Repeater switch: update called (refresh=True)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Flood Sensor (temperature): should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] temperature upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] light: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] humidity upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] 97 Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 1: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Skylight Ctrl Temp: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Gate Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 2: should_poll called (should_poll=False)
2021-02-22 11:39:12 INFO (MainThread) [homeassistant.components.vera] Aeon Z-Stick: should_poll called (should_poll=True)
2021-02-22 11:39:12 INFO (SyncWorker_6) [homeassistant.components.vera] Aeon Z-Stick: update called (refresh=True)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Flood Sensor (temperature): should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Skylight Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] temperature upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] light: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] humidity upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] 97 Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 1: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Skylight Ctrl Temp: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Gate Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 2: should_poll called (should_poll=False)
2021-02-22 11:39:17 INFO (MainThread) [homeassistant.components.vera] Aeon Z-Stick: should_poll called (should_poll=True)
2021-02-22 11:39:17 INFO (SyncWorker_0) [homeassistant.components.vera] Aeon Z-Stick: update called (refresh=True)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Flood Sensor (temperature): should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Skylight Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] temperature upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] light: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] humidity upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] 97 Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 1: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Skylight Ctrl Temp: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Gate Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 2: should_poll called (should_poll=False)
2021-02-22 11:39:22 INFO (MainThread) [homeassistant.components.vera] Aeon Z-Stick: should_poll called (should_poll=True)
2021-02-22 11:39:22 INFO (SyncWorker_5) [homeassistant.components.vera] Aeon Z-Stick: update called (refresh=True)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Flood Sensor (temperature): should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Skylight Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] temperature upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] light: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] humidity upstairs: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] UV Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] 97 Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Rain Sensor: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] SmartImplant Ext T: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 1: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Skylight Ctrl Temp: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Gate Temperature: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Temperature Sensor 2: should_poll called (should_poll=False)
2021-02-22 11:39:27 INFO (MainThread) [homeassistant.components.vera] Aeon Z-Stick: should_poll called (should_poll=True)
2021-02-22 11:39:27 INFO (SyncWorker_1) [homeassistant.components.vera] Aeon Z-Stick: update called (refresh=True)

You can see all the calls to should_poll and in the case of Aeon Z-Stick and Repeater switchwhich are not connected you can see the extra update.

You can also see the pyvera poll / event handling - and the updates that are called via that process. Sensors look to refresh more frequently than switches - but I see both doing as expected in my setup

So not sure what's happening in your setup. It could be an installation issue (it can be hard in a customised HA to make sure you have exactly what you want running) - or it could be your vera setup / devices are behaving differently.

Probably easiest to wait for the next HA release - and then happy to take a look if yours is not behaving as expected.

tgrusendorf commented 3 years ago

I'm definitely seeing different behaviour with the calling of should_poll here. I decided to clear off an SD card and try the version of HA from the dev channel (core-2021.4.0.dev20210228 is what I have installed now for testing). I also confirmed that I have the latest version of pyvera installed.

Is there any chance that you had one or more Vera devices already in a comm failure state when you are starting HA?

I've added a stack trace to the should_poll logging so that I can see what calls it. Here's what I have found:

If I start HA with any Vera device already in a comm failure state, I see results similar to yours. The entity platform regularly calls should_poll for all Vera devices in that particular domain (e.g. all Vera switches). If I start HA with no Vera devices in a comm failure state, I see no calls to should_poll after setup is done. In that case, a Vera device transitioning to comm failure after HA is running doesn't trigger polling of that device because nothing is watching should_poll at that point.

I hope that makes sense. It's been interesting digging into entity_platform and trying to figure out how it is working.

tgrusendorf commented 3 years ago

I found a closed architecture issue that relates. It confirms that should_poll should not change during the lifetime of an entity.

pavoni commented 3 years ago

I have a long term failed device - so that’s quite possible.

Thanks for the link...

pavoni commented 3 years ago

@tgrusendorf Thanks for doing the research.

I'll refactor slightly to try and make this work.

BTW I've been experimenting with moving a few of my devices across to zwave-js using the zwawe-js-mqtt addon that has a gui for setup and configutation.

So far the results are really good - much easier to configure devices - and much easier entity setup. Some of my devices that never worked properly in Vera are also working better.

I will test performance next.

pavoni commented 3 years ago

I still need to test this works as I expect. But if you are able to try it in your setup - please do!

https://github.com/home-assistant/core/pull/47854

tgrusendorf commented 3 years ago

I will give it a try. I also tried a slightly different approach this week that has been working well. I modified pyvera VeraDevice.should_poll to always return True. The HASS VeraDevice.update method was already only calling refresh if not self.available. This way I didn't have to modify the HASS component.

tgrusendorf commented 3 years ago

Thanks for the tip on zwawe-js-mqtt. When I saw you have a Z-Stick I was wondering if you had tried other non-Vera integrations. I haven't read everything yet, but does it look like zwawe-js-mqtt is going to be the primary method of integrating OpenZWave in HASS?

pavoni commented 3 years ago

I've been waiting for the HA zwave technologies to settle for a while, and finally looks like they have, so thought I'd try it.

Using an unsupported infrastructure always worries me - and it's getting hard to get new devices to work in Vera.

Having a controller that understands the devices is really great (all the device params are already there in the controller).

So yes - I suspect zwave-js is the way forward.

Currently you can use either zwave-js or zwave-js-mqtt addons to provide the websocket back end - both using the zwave-js library. zwave-js-mqtt has a nice GUI - and you can turn off the mqtt service anyway so it just provides a websocket api.

I tried a few ways of moving things before I decided just running both vera and zwave-js and re pairing devices as I go was the best and safest.

There are a couple of my devices that zwave-js doesn't yet support - but they are on their roadmap.

tgrusendorf commented 3 years ago

I checked out the dev branch of HA today, and I'm confused by the commit that ended up being merged into the dev branch. It still contains:

    def should_poll(self) -> bool:
        """Get polling requirement from vera device."""
        return self.vera_device.

But the comments indicated the property should be removed as it defaults to True. It looks like maybe just your change was removed instead of the entire property?

pavoni commented 3 years ago

Thanks for the heads up. Looks like I messed up the rebase. Will fix!