JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
183 stars 41 forks source link

[Bug]: PushButton sends timestamp as state for both "pressed" and "unpressed" events #299

Open PavelPawlowski opened 2 weeks ago

PavelPawlowski commented 2 weeks ago

Describe the bug

When a PushButton is Pressed in Loxone, the corresponding button object in HomeAssistant for both "Pressed" and "Unpressed" states have a timestamp in ithe state. So it is not possbile to distinguish those two events in any way as the current satate is nowehere available. (Previously when the PushButton was represented by switch in HA, it worked fine).

The state should be on / off or pressed / unpressed. Or something what would allow to distinguish the two event types. Or Send only a single even on Press instaed of two events.

Button Pressed Event Detail

{
  "payload": "2024-08-26T15:29:48.446374+00:00",
  "data": {
    "entity_id": "button.loxone_button_press_demo",
    "old_state": {
      "entity_id": "button.loxone_button_press_demo",
      "state": "2024-08-26T15:25:16.990973+00:00",
      "attributes": {
        "uuid": "182b9d23-01ca-2dda-ffffd1ffb7f86d13",
        "state_uuid": "182b9d23-01ca-2dd9-ffffa93911e485c3",
        "room": "Statusy",
        "category": "Ovládání",
        "device_type": "Pushbutton",
        "platform": "loxone",
        "friendly_name": "loxone_button_press_demo"
      },
      "last_changed": "2024-08-26T15:25:16.990994+00:00",
      "last_reported": "2024-08-26T15:29:48.370564+00:00",
      "last_updated": "2024-08-26T15:25:16.990994+00:00",
      "context": {
        "id": "01J67MN6SYP2S180BWVF1QJHSD",
        "parent_id": null,
        "user_id": null
      }
    },
    "new_state": {
      "entity_id": "button.loxone_button_press_demo",
      "state": "2024-08-26T15:29:48.446374+00:00",
      "attributes": {
        "uuid": "182b9d23-01ca-2dda-ffffd1ffb7f86d13",
        "state_uuid": "182b9d23-01ca-2dd9-ffffa93911e485c3",
        "room": "Statusy",
        "category": "Ovládání",
        "device_type": "Pushbutton",
        "platform": "loxone",
        "friendly_name": "loxone_button_press_demo"
      },
      "last_changed": "2024-08-26T15:29:48.446550+00:00",
      "last_reported": "2024-08-26T15:29:48.446550+00:00",
      "last_updated": "2024-08-26T15:29:48.446550+00:00",
      "context": {
        "id": "01J67MXFTFQ2HJ8NR7WNZS1C1Q",
        "parent_id": null,
        "user_id": "5244dadddac14f1b9c220a7741163d8a"
      },
      "timeSinceChangedMs": 15
    }
  },
  "topic": "button.loxone_button_press_demo",
  "_msgid": "ed64071f15c2f2c8"
}

Button UnPressed Event Detail

{
  "payload": "2024-08-26T15:29:49.411075+00:00",
  "data": {
    "entity_id": "button.loxone_button_press_demo",
    "old_state": {
      "entity_id": "button.loxone_button_press_demo",
      "state": "2024-08-26T15:29:48.446374+00:00",
      "attributes": {
        "uuid": "182b9d23-01ca-2dda-ffffd1ffb7f86d13",
        "state_uuid": "182b9d23-01ca-2dd9-ffffa93911e485c3",
        "room": "Statusy",
        "category": "Ovládání",
        "device_type": "Pushbutton",
        "platform": "loxone",
        "friendly_name": "loxone_button_press_demo"
      },
      "last_changed": "2024-08-26T15:29:48.446550+00:00",
      "last_reported": "2024-08-26T15:29:48.446550+00:00",
      "last_updated": "2024-08-26T15:29:48.446550+00:00",
      "context": {
        "id": "01J67MXFTFQ2HJ8NR7WNZS1C1Q",
        "parent_id": null,
        "user_id": "5244dadddac14f1b9c220a7741163d8a"
      }
    },
    "new_state": {
      "entity_id": "button.loxone_button_press_demo",
      "state": "2024-08-26T15:29:49.411075+00:00",
      "attributes": {
        "uuid": "182b9d23-01ca-2dda-ffffd1ffb7f86d13",
        "state_uuid": "182b9d23-01ca-2dd9-ffffa93911e485c3",
        "room": "Statusy",
        "category": "Ovládání",
        "device_type": "Pushbutton",
        "platform": "loxone",
        "friendly_name": "loxone_button_press_demo"
      },
      "last_changed": "2024-08-26T15:29:49.411206+00:00",
      "last_reported": "2024-08-26T15:29:49.411206+00:00",
      "last_updated": "2024-08-26T15:29:49.411206+00:00",
      "context": {
        "id": "01J67MXFTFQ2HJ8NR7WNZS1C1Q",
        "parent_id": null,
        "user_id": "5244dadddac14f1b9c220a7741163d8a"
      },
      "timeSinceChangedMs": 13
    }
  },
  "topic": "button.loxone_button_press_demo",
  "_msgid": "c546c35ad793d131"
}

Firmware of your Miniserver

11.1.9.14

HomeAssistant install method

HACS

Version of HomeAssistant

2024.8.3

Version of Pyloxone

0.6.14

Update pyloxone

Yes, updated to the latest version:

Log

Settings for the log can be found on the main page under the section Log Configuration

PavelPawlowski commented 2 weeks ago

It would be fine with the timestamp in the state, if only one event would be sent to HA, but there are two events being sent to HA within several milliseconds.

JoDehli commented 2 weeks ago

@PavelPawlowski no it should behave exactly like other buttons. I see no solution to change that.

JoDehli commented 2 weeks ago

@PavelPawlowski see also https://github.com/JoDehli/PyLoxone/issues/294#issuecomment-2272765678

JoDehli commented 2 weeks ago

The button entity is stateless. https://developers.home-assistant.io/docs/core/entity/button/

PavelPawlowski commented 2 weeks ago

I understand that it is stateless. Then it is fine when the button is pressed and as a state a timestamp is sent.

But the problem is that a single press of the button in loxone sends two events into HA, so like two presses in a row. (with original switch implementation it was fine, butecause first event was "on" and second event was "off". But with the PushButton, two events with timestamp arrive instead of single event.)

Like in the code example I've reported.

With Single Press of button:

First event received in HA:

{
  "payload": "2024-08-26T15:29:48.446374+00:00"
}

Second event received in HA a second later

{
  "payload": "2024-08-26T15:29:49.411075+00:00"
}

Other PressButtons in HA when pressed, theye send single event with timestamp as state.

gigatexel commented 1 week ago

I understand that it is stateless. Then it is fine when the button is pressed and as a state a timestamp is sent.

But the problem is that a single press of the button in loxone sends two events into HA, so like two presses in a row. (with original switch implementation it was fine, butecause first event was "on" and second event was "off". But with the PushButton, two events with timestamp arrive instead of single event.)

Like in the code example I've reported.

With Single Press of button:

First event received in HA:

{
  "payload": "2024-08-26T15:29:48.446374+00:00"
}

Second event received in HA a second later

{
  "payload": "2024-08-26T15:29:49.411075+00:00"
}

Other PressButtons in HA when pressed, theye send single event with timestamp as state.

As you state in your reply: the problem is that Loxone Miniserver sends two events. There should be only one. Your loggings confirm that there is no way do distinguish between the Loxone Button-down and Loxone Button-up. This is something that Loxone should fix.

What are you trying to accomplish? Maybe we can help.