jason0x43 / hacs-hubitat

A Hubitat integration for Home Assistant
MIT License
191 stars 46 forks source link

Tuya Scene Switch not working in HA #220

Closed cschmittiey closed 1 year ago

cschmittiey commented 1 year ago

First of all, thanks for your awesome work! I use this with some zigbee window sensors and it's been awesome to have around.

I ran into some issues with adding a new Tuya Scene Switch though:

I'm using this device: https://www.aliexpress.us/item/3256801318422900.html At first I was using the Tuya Scene Switch driver built into the hubitat, but switched to this in hopes it would help: https://community.hubitat.com/t/release-tuya-scene-switch-ts004f-driver-w-healthstatus/92823

but I'm still not receiving the events in home assistant - I'm not sure what I'm missing. I see that the Maker API posts the events to home assistant when I enable debug logging:

2023-07-03 18:19:08.602 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'pushed', 'value': '1', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 1 was pushed', 'unit': None, 'type': 'physical', 'data': '{"buttonNumber":1}'}
2023-07-03 18:19:08.602 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating pushed of 6 to 1 (None)
2023-07-03 18:19:08.603 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.PUSHED: 'pushed'>, 'value': '1', 'unit': None, 'description': 'button 1 was pushed', 'type': 'physical', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}
2023-07-03 18:19:11.456 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'pushed', 'value': '2', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 2 was pushed', 'unit': None, 'type': 'physical', 'data': '{"buttonNumber":2}'}
2023-07-03 18:19:11.456 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating pushed of 6 to 2 (None)
2023-07-03 18:19:11.457 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.PUSHED: 'pushed'>, 'value': '2', 'unit': None, 'description': 'button 2 was pushed', 'type': 'physical', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}
2023-07-03 18:19:12.471 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'pushed', 'value': '3', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 3 was pushed', 'unit': None, 'type': 'physical', 'data': '{"buttonNumber":3}'}
2023-07-03 18:19:12.471 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating pushed of 6 to 3 (None)
2023-07-03 18:19:12.472 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.PUSHED: 'pushed'>, 'value': '3', 'unit': None, 'description': 'button 3 was pushed', 'type': 'physical', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}
2023-07-03 18:19:13.579 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'pushed', 'value': '4', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 4 was pushed', 'unit': None, 'type': 'physical', 'data': '{"buttonNumber":4}'}
2023-07-03 18:19:13.579 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating pushed of 6 to 4 (None)
2023-07-03 18:19:13.580 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.PUSHED: 'pushed'>, 'value': '4', 'unit': None, 'description': 'button 4 was pushed', 'type': 'physical', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}
2023-07-03 18:21:01.752 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'doubleTapped', 'value': '3', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 3 was doubleTapped', 'unit': None, 'type': 'digital', 'data': '{"buttonNumber":3}'}
2023-07-03 18:21:01.752 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating doubleTapped of 6 to 3 (None)
2023-07-03 18:21:01.753 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.DOUBLE_TAPPED: 'double_tapped'>, 'value': '3', 'unit': None, 'description': 'button 3 was doubleTapped', 'type': 'digital', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}
2023-07-03 18:21:03.902 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'doubleTapped', 'value': '3', 'displayName': 'Living Room Buttons', 'deviceId': '6', 'descriptionText': 'button 3 was doubleTapped', 'unit': None, 'type': 'digital', 'data': '{"buttonNumber":3}'}
2023-07-03 18:21:03.902 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating doubleTapped of 6 to 3 (None)
2023-07-03 18:21:03.903 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '6', 'device_name': 'Living Room Buttons', 'attribute': <EventName.DOUBLE_TAPPED: 'double_tapped'>, 'value': '3', 'unit': None, 'description': 'button 3 was doubleTapped', 'type': 'digital', 'hub': 'c1948409', 'ha_device_id': 'c505633a70a84fb6f3f725f253246abfe19ccb7764adcfeae4742a60cb9ec6dd::6'}

The entities in home assistant just show up as unavailable in the UI however firefox_UxiBq64d57 firefox_i6KyRrt8AM

Here's the JSON for the device on the Maker API:

{
    "name": "Tuya Scene Switch TS004F",
    "label": "Living Room Buttons",
    "type": "Tuya Scene Switch TS004F",
    "id": "6",
    "date": "2023-07-04T00:21:06+0000",
    "model": null,
    "manufacturer": null,
    "room": "Living Room",
    "capabilities": [
      "Configuration",
      "PowerSource",
      "Refresh",
      "Battery",
      "HoldableButton",
      "ReleasableButton",
      "PushableButton",
      "DoubleTapableButton",
      "HealthCheck"
    ],
    "attributes": {
      "supportedButtonValues": "[\"pushed\",\"double\",\"held\"]",
      "dataType": "NUMBER",
      "values": null,
      "checkInterval": null,
      "pushed": "4",
      "powerSource": "battery",
      "held": "3",
      "switchMode": null,
      "battery": "100",
      "doubleTapped": "3",
      "numberOfButtons": "4",
      "batteryVoltage": "3.0",
      "healthStatus": "online",
      "released": null
    },
    "commands": [
      {
        "command": "configure"
      },
      {
        "command": "doubleTap"
      },
      {
        "command": "hold"
      },
      {
        "command": "ping"
      },
      {
        "command": "push"
      },
      {
        "command": "refresh"
      },
      {
        "command": "release"
      }
    ]
  }
cschmittiey commented 1 year ago

My bad - didn't realize i was supposed to use the device triggers in automations and not look for state in the UI.

jason0x43 commented 1 year ago

Sorry for not getting back to you on this. You're right, device triggers are the way to go here. Push button devices in HA are event emitters, so you typically deal with the events directly (or via device triggers) rather than using a stateful entity.