Closed stefankns closed 1 month ago
After looking into this, I think the best way is to implement the remote attribute as event entity
This should then allow it to be used in automations easily.
Latest Beta implements an event entity for the remote.
See https://www.home-assistant.io/integrations/event/ for details.
Since I can only mock the device statically and can not simulate changes of the attributes, I can't test if and how it works. Please test and let me know.
Thanks for the quick implementation! I installed the beta2 and gave it a try:
After installation and restart the "Wandsender" devices have now an event entity like this:
In the development tools this looks like this:
The state is shown as unknown and it does not change when pressing a button on the remote. According to https://www.home-assistant.io/integrations/event/ I expected a timestamp for a button device_class. Also the log from the screenshot above does not get a new line. For another button device with device_class button (implemented via the Homekit integration) I can see logbook lines as well as timestamps in those dialogs.
So there seems to be no update getting through. I activated logging as you recommended for the pymee module and I get the following output when pressing a button: (it is the central STOP button)
2024-05-31 11:07:50.436 DEBUG (MainThread) [pymee] {'attribute': {'id': 112, 'node_id': 23, 'instance': 0, 'minimum': 0, 'maximum': 9, 'current_value': 3.0, 'target_value': 3.0, 'last_value': 0.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 0, 'type': 300, 'state': 1, 'last_changed': 1717146470, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': ''}} 2024-05-31 11:07:50.436 INFO (MainThread) [pymee] Updating attribute 112 2024-05-31 11:07:50.512 INFO (MainThread) [pymee] Set value: Device: 22 Attribute: 105 To: 2.0 2024-05-31 11:07:50.540 DEBUG (MainThread) [pymee] {'attribute': {'id': 105, 'node_id': 22, 'instance': 0, 'minimum': 0, 'maximum': 4, 'current_value': 0.0, 'target_value': 2.0, 'last_value': 2.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 1, 'type': 135, 'state': 4, 'last_changed': 1717146340, 'changed_by': 2, 'changed_by_id': 2, 'based_on': 1, 'data': '', 'name': '', 'options': {'can_observe': [300], 'automations': ['toggle']}}} 2024-05-31 11:07:50.540 INFO (MainThread) [pymee] Updating attribute 105 2024-05-31 11:07:50.961 DEBUG (MainThread) [pymee] {'attribute': {'id': 112, 'node_id': 23, 'instance': 0, 'minimum': 0, 'maximum': 9, 'current_value': 0.0, 'target_value': 0.0, 'last_value': 3.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 0, 'type': 300, 'state': 1, 'last_changed': 1717146470, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': ''}} 2024-05-31 11:07:50.961 INFO (MainThread) [pymee] Updating attribute 112
After a quick pause there are dropping in some more lines that seem to be related, because it is reproducible:
2024-05-31 11:07:52.066 DEBUG (MainThread) [pymee] {'attribute': {'id': 105, 'node_id': 22, 'instance': 0, 'minimum': 0, 'maximum': 4, 'current_value': 2.0, 'target_value': 2.0, 'last_value': 0.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 1, 'type': 135, 'state': 1, 'last_changed': 1717146472, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': '', 'options': {'can_observe': [300], 'automations': ['toggle']}}} 2024-05-31 11:07:52.066 INFO (MainThread) [pymee] Updating attribute 105 2024-05-31 11:08:01.813 DEBUG (MainThread) [pymee] {'attribute': {'id': 19, 'node_id': -1, 'instance': 0, 'minimum': 0, 'maximum': 100, 'current_value': 15.0, 'target_value': 15.0, 'last_value': 9.0, 'unit': '%25', 'step_value': 0.1, 'editable': 0, 'type': 312, 'state': 1, 'last_changed': 1717146481, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': '', 'options': {'history': {'day': 1, 'week': 26, 'month': 6}}}} 2024-05-31 11:08:01.814 INFO (MainThread) [pymee] Updating attribute 19 2024-05-31 11:08:02.246 DEBUG (MainThread) [pymee] {'attribute': {'id': 105, 'node_id': 22, 'instance': 0, 'minimum': 0, 'maximum': 4, 'current_value': 0.0, 'target_value': 0.0, 'last_value': 2.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 1, 'type': 135, 'state': 1, 'last_changed': 1717146482, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': '', 'options': {'can_observe': [300], 'automations': ['toggle']}}} 2024-05-31 11:08:02.246 INFO (MainThread) [pymee] Updating attribute 105
I also created an automation as described in https://www.home-assistant.io/integrations/event/, but nothing is triggered.
To listen to events in general, in my understanding, the development tools -> page events can be used:
Do you have a hint, what event type I would have to put into the "Hören auf Ereignisse" box?
Hmmm, then I mabye haven't understood correctly how this entity works. I'll have a look at the logs and try to figure out where my error is.
It seems, that I forgot to implement the listener for the change of the attribute in HA. Can you try to exchange your event.py in the HA-Homee directory (config/custom_components/homee) with this version and try? This way I don't need to publish a beta for everyone while we try to figure it out.
I downloaded the code for event.py and replaced it in the file you mentioned. Then I restarted HA. No change in behaviour but the following ends up in the logs:
2024-05-31 16:04:58.521 DEBUG (MainThread) [pymee] {'attribute': {'id': 112, 'node_id': 23, 'instance': 0, 'minimum': 0, 'maximum': 9, 'current_value': 3.0, 'target_value': 3.0, 'last_value': 0.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 0, 'type': 300, 'state': 1, 'last_changed': 1717164298, 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': ''}} 2024-05-31 16:04:58.522 INFO (MainThread) [pymee] Updating attribute 112 2024-05-31 16:04:58.531 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 134, in run await self.open_ws() File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 181, in open_ws raise exceptions[0] File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 199, in _ws_receive_handler await self._ws_on_message(msg) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 232, in _ws_on_message await self._handle_message(json.loads(msg)) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 304, in _handle_message await self._handle_attribute_change(msg["attribute"]) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 334, in _handle_attribute_change node._update_attribute(attribute_data) File "/usr/local/lib/python3.12/site-packages/pymee/model.py", line 284, in _update_attribute listener(self, attribute) for listener in self._onChangedListeners ^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: HomeeEvent._async_handle_event() takes 2 positional arguments but 3 were given 2024-05-31 16:04:58.663 INFO (MainThread) [pymee] Set value: Device: 22 Attribute: 105 To: 2.0
Thanks, that shows I am on the right track. I updated event.py again - that should fix the error in the log. Let's see if this was the only one...
Sorry, took some time to understand that you probably refer to the same link. I updated event.py again. No startup error. On button press now:
2024-05-31 17:08:42.618 INFO (MainThread) [pymee] Updating attribute 112 2024-05-31 17:08:42.630 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 134, in run await self.open_ws() File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 181, in open_ws raise exceptions[0] File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 199, in _ws_receive_handler await self._ws_on_message(msg) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 232, in _ws_on_message await self._handle_message(json.loads(msg)) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 304, in _handle_message await self._handle_attribute_change(msg["attribute"]) File "/usr/local/lib/python3.12/site-packages/pymee/__init__.py", line 334, in _handle_attribute_change node._update_attribute(attribute_data) File "/usr/local/lib/python3.12/site-packages/pymee/model.py", line 284, in _update_attribute listener(self, attribute) for listener in self._onChangedListeners ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/homee/event.py", line 68, in _async_handle_event self._trigger_event(int(event.current_value)) File "/usr/src/homeassistant/homeassistant/components/event/__init__.py", line 153, in _trigger_event raise ValueError(f"Invalid event type {event_type} for {self.entity_id}") ValueError: Invalid event type 3 for event.wandsender_buro_taste 2024-05-31 17:08:42.738 INFO (MainThread) [pymee] Set value: Device: 22 Attribute: 105 To: 2.0
No problem, was away anyway... ;-) so the event function expects a string iso an integer. Changed that. Thanks for the testing, we might need some more iterations here.
Thx. Testing it right now.
Progress:
Something is updated. Trying to find out, what :-)
Looks good. The small number below the timestamp indicates the button ID:
Also the automation I configured according to https://www.home-assistant.io/integrations/event/ is triggered.
Development tools look good as well:
Now I only need to understand, what event type I need to use to catch the events (I am mostly using Node RED for automations using an events listener block from the websocket API). I find it hard to find info on the event types in general in the documentation.
I tried to have the events giving the text in the list you provided earlier. This seems not to work, but at least the events themselves are firing. I try to figure that out later.
At least I managed to catch one event in the development tools when listening to "*" (all events), so this is what is generated in HA:
And I start to figure out how to access it in Node RED as well. It is implemented as a button event with a state (not a stateless one!). So in Node RED I can simply set a listener to the event entity. It works perfect. The data I get there is consistent to the HA event:
That means, the event is firing correctly and now I can focus on making it more descriptive? I tried somthing on that - can you try again please.
Everything still works with the new version. But the states are still numbers.
Ah, stupid me - now the localization files need updating... DOH. https://github.com/Taraman17/hass-homee/blob/dev/custom_components/homee/strings.json And the two files in the translations directory: https://github.com/Taraman17/hass-homee/tree/dev/custom_components/homee/translations
Yep!!! Cool.
Catched it when pressing "stop":
Do you think this is a good way to handle this remote after all?
Thanks for testing.
Thanks a lot! Works like a charm. I think it is a great way of handling the remote and it fits very well into the HA philosophy, as far as I can judge it. I have already moved my logic from Homee API calls in Node RED to the event listeners connected to the new event entities and all my 12 devices work perfectly. I also tested all buttons with all press-variants (short, long). All event types work and the texts are displayed correctly as well. It was a pleasure to do the testing :-)
One comment about the Warema device titles on the page https://github.com/Taraman17/hass-homee/wiki. You might want to remove the numbers in the brackets behind the Warema device classes. They just represent the serial number of the device that was used to create the logs that you based the profile description on.
Again, thanks a lot. Great job!
Fixed with Release 2.9.4
Device Type: Remote Control
Log:
2024-05-14 18:48:06.116 INFO (MainThread) [custom_components.homee] Found node Wandsender Wohnzimmer Festverglasung, with following Data: {'id': 31, 'name': 'Wandsender%20Wohnzimmer%20Festverglasung', 'profile': 41, 'image': 'default', 'favorite': 0, 'order': 29, 'protocol': 23, 'routing': 0, 'state': 1, 'state_changed': [1715356788](tel:1715356788), 'added': [1615396304](tel:1615396304), 'history': 1, 'cube_type': 14, 'note': 'WAREMA%20Wandsender%20basic%20%281012296%29', 'services': 0, 'phonetic_name': '', 'owner': 2, 'security': 0, 'attributes': [{'id': 158, 'node_id': 31, 'instance': 0, 'minimum': 0, 'maximum': 9, 'current_value': 0.0, 'target_value': 0.0, 'last_value': 2.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 0, 'type': 300, 'state': 1, 'last_changed': [1713470190](tel:1713470190), 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': '', 'options': {'observed_by': [145]}}, {'id': 159, 'node_id': 31, 'instance': 0, 'minimum': 0, 'maximum': 0, 'current_value': 0.0, 'target_value': 0.0, 'last_value': 0.0, 'unit': 'text', 'step_value': 1.0, 'editable': 0, 'type': 45, 'state': 1, 'last_changed': [1615396304](tel:1615396304), 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '[07319121012](tel:07319121012)', 'name': ''}, {'id': 160, 'node_id': 31, 'instance': 0, 'minimum': 0, 'maximum': 1, 'current_value': 0.0, 'target_value': 0.0, 'last_value': 0.0, 'unit': 'n%2Fa', 'step_value': 1.0, 'editable': 1, 'type': 170, 'state': 1, 'last_changed': [1621765009](tel:1621765009), 'changed_by': 1, 'changed_by_id': 0, 'based_on': 1, 'data': '', 'name': ''}, {'id': 236, 'node_id': 31, 'instance': 0, 'minimum': 0, 'maximum': 1, 'current_value': 1.0, 'target_value': 1.0, 'last_value': 0.0, 'unit': '', 'step_value': 1.0, 'editable': 1, 'type': 385, 'state': 1, 'last_changed': 0, 'changed_by': 0, 'changed_by_id': 0, 'based_on': 0, 'data': '', 'name': ''}]}
Picture:![IMG_0883](https://github.com/Taraman17/hass-homee/assets/91949743/bc2b09bb-2d85-40d5-b4ec-0e45475d956e)
Buttons: Up / Down / Stop Left small button: C (comfort button) Right small button: A (Automatic mode button)
Screenshots Homee-GUI:
![IMG_0921](https://github.com/Taraman17/hass-homee/assets/91949743/acb1eed4-a971-4829-a7fa-16b2b2e15421)
Actual Home Assistant representation:![IMG_0084](https://github.com/Taraman17/hass-homee/assets/91949743/36a5c6e3-2215-4a12-8ba5-eb0ff516579c)
From an own Node-RED implementation based on a homee api connection I know that the different buttons generate a message with the attribute type 300 and the following target_values: 1 = up 4 = up (gehalten/long-press) 3 = stop 6 = stop (gehalten/long-press) 2 = down 5 = down (gehalten/long-press) 7 = C-Button 9 = A-Button The target_value returns to 0, when released