make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.31k stars 514 forks source link

MoesHouse RGB socket - brightness problem #691

Closed vampywiz17 closed 1 year ago

vampywiz17 commented 1 year ago

Describe the bug

If i set the brightness on Lovelace UI, it set it back to 100%, but the change is happen. For example, if i set the value to 50%, my socket brightness set to 50%, but the entity value switch back to 100%.

To Reproduce

Set brightness different than 100%

Expected behavior Set brightness to a custom value and the entity is remember it.

Additional context

https://user-images.githubusercontent.com/14281430/236859272-4c4035dc-95af-465b-a6a0-a783ec033ab6.mp4


  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.5.2",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.11",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Budapest",
    "os_name": "Linux",
    "os_version": "6.1.25",
    "supervisor": "2023.04.1",
    "host_os": "Home Assistant OS 10.1",
    "docker_version": "23.0.3",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "pollen_hu": {
      "version": "0.2.0",
      "requirements": []
    },
    "sonarr_upcoming_media": {
      "version": "0.2.7",
      "requirements": []
    },
    "webrtc": {
      "version": "v3.1.0",
      "requirements": []
    },
    "climate_group": {
      "version": "0.4.2",
      "requirements": []
    },
    "nodered": {
      "version": "1.2.0",
      "requirements": []
    },
    "alarmo": {
      "version": "v1.9.9",
      "requirements": []
    },
    "openhasp": {
      "version": "0.6.5",
      "requirements": [
        "jsonschema>=3.2.0"
      ]
    },
    "xiaomi_miot": {
      "version": "0.7.8",
      "requirements": [
        "construct==2.10.56",
        "python-miio>=0.5.6",
        "micloud>=0.3"
      ]
    },
    "tuya_local": {
      "version": "2022.5.0",
      "requirements": [
        "pycryptodome~=3.17",
        "tinytuya==1.12.6"
      ]
    },
    "wundergroundpws": {
      "version": "2.0.1",
      "requirements": []
    },
    "mold_risk_index": {
      "version": "1.0.0",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "tuya_local",
    "name": "Tuya Local",
    "codeowners": [
      "@make-all"
    ],
    "config_flow": true,
    "dependencies": [],
    "documentation": "https://github.com/make-all/tuya-local",
    "integration_type": "device",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/make-all/tuya-local/issues",
    "requirements": [
      "pycryptodome~=3.17",
      "tinytuya==1.12.6"
    ],
    "version": "2022.5.0",
    "is_built_in": false
  },
  "data": {
    "name": "MoesHouse RGB socket",
    "type": "moes_rgb_socket",
    "device_id": "**REDACTED**",
    "local_key": "**REDACTED**",
    "host": "**REDACTED**",
    "protocol_version": 3.3,
    "api_version_set": 3.3,
    "api_version_used": 3.3,
    "api_working": true,
    "status": {},
    "cached_state": {
      "updated_at": 1683557455.7718694,
      "1": false,
      "2": "colour",
      "3": 255,
      "4": 30,
      "5": "ffbf00002dff8c",
      "6": "fffcf7002608ff",
      "7": "ffff320100ff00",
      "8": "ffff3203ff000000ff000000ff",
      "9": "ffff3201ff0000",
      "10": "ffff3205ff000000ff00ffff00ff00ff0000ff",
      "101": true,
      "104": 0,
      "105": 0,
      "106": 2388
    },
    "pending_state": {},
    "connected": true,
    "force_dps": [
      104,
      105,
      106
    ],
    "home_assistant": {
      "name": "MoesHouse RGB socket",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "outlet",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "switch.moeshouse_rgb_socket",
            "state": "on",
            "attributes": {
              "device_class": "outlet",
              "friendly_name": "MoesHouse RGB socket"
            },
            "last_changed": "2023-05-08T14:50:43.599090+00:00",
            "last_updated": "2023-05-08T14:50:43.599090+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "current",
          "icon": null,
          "unit_of_measurement": "mA",
          "state": {
            "entity_id": "sensor.moeshouse_rgb_socket_current",
            "state": "0",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "mA",
              "device_class": "current",
              "friendly_name": "MoesHouse RGB socket Current"
            },
            "last_changed": "2023-05-08T14:50:43.598496+00:00",
            "last_updated": "2023-05-08T14:50:43.598496+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "power",
          "icon": null,
          "unit_of_measurement": "W",
          "state": {
            "entity_id": "sensor.moeshouse_rgb_socket_power",
            "state": "0.0",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "W",
              "device_class": "power",
              "friendly_name": "MoesHouse RGB socket Power"
            },
            "last_changed": "2023-05-08T14:50:43.598688+00:00",
            "last_updated": "2023-05-08T14:50:43.598688+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "voltage",
          "icon": null,
          "unit_of_measurement": "V",
          "state": {
            "entity_id": "sensor.moeshouse_rgb_socket_voltage",
            "state": "238.8",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "V",
              "device_class": "voltage",
              "friendly_name": "MoesHouse RGB socket Voltage"
            },
            "last_changed": "2023-05-08T14:50:43.598954+00:00",
            "last_updated": "2023-05-08T14:50:43.598954+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "light.moeshouse_rgb_socket_night_light",
            "state": "off",
            "attributes": {
              "effect_list": [
                "Scene 1",
                "Scene",
                "Scene 4",
                "Scene 2",
                "Scene 3"
              ],
              "supported_color_modes": [
                "rgbw",
                "white"
              ],
              "unknown_4": 30,
              "scene_data": "fffcf7002608ff",
              "flash_scene_1": "ffff320100ff00",
              "flash_scene_2": "ffff3203ff000000ff000000ff",
              "flash_scene_3": "ffff3201ff0000",
              "flash_scene_4": "ffff3205ff000000ff00ffff00ff00ff0000ff",
              "friendly_name": "MoesHouse RGB socket Night light",
              "supported_features": 4
            },
            "last_changed": "2023-05-08T14:50:55.772220+00:00",
            "last_updated": "2023-05-08T14:50:55.772220+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "min",
          "state": {
            "entity_id": "number.moeshouse_rgb_socket_timer",
            "state": "unknown",
            "attributes": {
              "min": 0.0,
              "max": 1440.0,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "min",
              "icon": "mdi:timer",
              "friendly_name": "MoesHouse RGB socket Timer"
            },
            "last_changed": "2023-05-08T14:50:43.598260+00:00",
            "last_updated": "2023-05-08T14:50:43.598260+00:00"
          }
        }
      ]
    }
  }
}```
make-all commented 1 year ago

dp 4 is listed in the config as unknown, and dp 3 as the brightness. Is this bulb perhaps using dp 4 for the brightness feedback, and dp3 is write-only? This would be annoying to deal with, but there may be a way.

vampywiz17 commented 1 year ago

@make-all

it might be the problem is that i change "color brightness" but read the "normal" brightness?

because if i change it, not the brightness change, but the color data.

image

because in the integration are two slider. color brightness and white brightness. If i set the white one, nothing happen. It only work when i set the color one.

image

make-all commented 1 year ago

Yes, the colour format of Tuya lights includes the brightness, so if you change the brightness dp at the same time, the lights become too dim too quickly (25% with the slider set to 50%), so the brightness dp is only set when in white mode.

The separate white and color sliders in the same UI are a recent change in HA, and I haven't actually figured out how they are supposed to work, as neither seems to work perfectly for me, but the main slider on the card does work as well as the single brightness slider did in the previous version of the dialog.

vampywiz17 commented 1 year ago

@make-all

single brightness slider is not working this RGB socket.

vampywiz17 commented 1 year ago

@make-all

Sorry, no time to check it, but i do it now :)

It much better, on new release. The unnecessary sliders are gone.

I found only two bugs. (it connected each other.)

  1. If i set the card slider, the "set it up" value is also jump back to 100. (but set the good brightness ). If i open the entity, the build in slider work good, but if i close and open again it also show 100%

not working: image

working: image

  1. It Forget the set it up value. If i set to 50%, the device remember this value if i switch it up again, but on HA interface i also see 100% (both card and opened entity)

Ok, it do some test on tuya iot portal.

This DP_id the color, it is true.

        "code": "colour_data",
        "dp_id": 5,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },

If i change the "V"value, it seems set the brightness correctly. it is a 1-255 slider, with 1 step. so it vould be good to use brightness value in HA.

make-all commented 1 year ago

I see the problem. When the light is in color mode, the brightness is set through the color_data dp, not the brightness dp. But when the brightness is read, it is always read from the brightness dp.

vampywiz17 commented 1 year ago

I see the problem. When the light is in color mode, the brightness is set through the color_data dp, not the brightness dp. But when the brightness is read, it is always read from the brightness dp.

exactly, yes.

edit:

The "white mode" i dont know what is, exactly. in tuya app, not exist similar option. only the color cycle and two slider "bright" and "cool".

345628049_629776852330569_1887061533162614588_n

make-all commented 1 year ago

Both Home Assistant and Tuya app hide the mode selection from the user, and change it in background based on what controls are changed. I did not expect a "Cool" slider for this light though, the logs and iot portal info when it was first added showed only a brightness and colour control, no color_temp.

Looking at the Tuya screenshot, the color wheel is only letting you choose Hue. So the "Cool" slider might be saturation.

vampywiz17 commented 1 year ago

Both Home Assistant and Tuya app hide the mode selection from the user, and change it in background based on what controls are changed. I did not expect a "Cool" slider for this light though, the logs and iot portal info when it was first added showed only a brightness and colour control, no color_temp.

Looking at the Tuya screenshot, the color wheel is only letting you choose Hue. So the "Cool" slider might be saturation.

vampywiz17 commented 1 year ago

It work well now thanks!!

Last thing. The white mode in HA interface not do anything, in this mode the brightness slider not work

seems Ids are not change at all.


  "result": {
    "category": "dj",
    "functions": [
      {
        "code": "switch_led",
        "dp_id": 1,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "bright_value",
        "dp_id": 3,
        "type": "Integer",
        "values": "{\"min\":25,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}"
      },
      {
        "code": "work_mode",
        "dp_id": 2,
        "type": "Enum",
        "values": "{\"range\":[\"white\",\"colour\",\"scene\",\"scene_1\",\"scene_2\",\"scene_3\",\"scene_4\"]}"
      },
      {
        "code": "colour_data",
        "dp_id": 5,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "scene_data",
        "dp_id": 6,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_1",
        "dp_id": 7,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_2",
        "dp_id": 8,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_3",
        "dp_id": 9,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_4",
        "dp_id": 10,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "switch",
        "dp_id": 101,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_1",
        "dp_id": 102,
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      }
    ],
    "status": [
      {
        "code": "switch_led",
        "dp_id": 1,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "work_mode",
        "dp_id": 2,
        "type": "Enum",
        "values": "{\"range\":[\"white\",\"colour\",\"scene\",\"scene_1\",\"scene_2\",\"scene_3\",\"scene_4\"]}"
      },
      {
        "code": "bright_value",
        "dp_id": 3,
        "type": "Integer",
        "values": "{\"min\":25,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}"
      },
      {
        "code": "colour_data",
        "dp_id": 5,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "scene_data",
        "dp_id": 6,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_1",
        "dp_id": 7,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_2",
        "dp_id": 8,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_3",
        "dp_id": 9,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "flash_scene_4",
        "dp_id": 10,
        "type": "Json",
        "values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
      },
      {
        "code": "switch",
        "dp_id": 101,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "cur_current",
        "dp_id": 104,
        "type": "Integer",
        "values": "{\"unit\":\"mA\",\"min\":0,\"max\":30000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "cur_power",
        "dp_id": 105,
        "type": "Integer",
        "values": "{\"unit\":\"W\",\"min\":0,\"max\":50000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "cur_voltage",
        "dp_id": 106,
        "type": "Integer",
        "values": "{\"unit\":\"V\",\"min\":0,\"max\":2500,\"scale\":0,\"step\":1}"
      },
      {
        "code": "countdown_1",
        "dp_id": 102,
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      }
    ]
  },
  "success": true,
  "t": 1684073608589,
  "tid": "7f982f3bf26111ed9b213e97a7ff9260"
}```
vampywiz17 commented 1 year ago
2023-05-15 22:51:54.333 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:53:01.053 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:55:00.886 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:55:57.430 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:56:59.204 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:58:01.119 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:58:58.107 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 22:59:54.863 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:00:56.928 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:01:58.492 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:02:55.346 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:04:01.980 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:05:08.974 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket
2023-05-15 23:06:05.687 ERROR (MainThread) [custom_components.tuya_local.device] Failed to update device dps for MoesHouse RGB socket

The device generate a lot of error message

vampywiz17 commented 1 year ago

The force update removal is fixed the issue :)

Thanks!