rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.83k stars 545 forks source link

Support Tuya Smart Star Projector #297

Open kireque opened 3 years ago

kireque commented 3 years ago

Having some issues integrating the Tuya Smart Star Projector.

Following dps config

{ 
    dps: 
        { 
            '20': true,           <-- overall power state, true - false
            '21': 'white',        <-- scene, color (when editing color settings), white (when editing laser settings) 
            '22': 10,             <-- laser brightness, range 10 - 1000
            '24': '0069035903e8', <-- color, color temperature
            '25': '06464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000',
            '26': 0,               <-- Unknown
            '101': 1000,          <-- rotation speed, range 1 - 1000
            '102': true,          <-- laser, true - false
            '103': true           <-- color, true - false
        }
}

I have the following config in HA:

host: !secret smart_star_projector_host
device_id: !secret smart_star_projector_id
local_key: !secret smart_star_projector_key
friendly_name: bedroom_kid_smart_star_projector
protocol_version: "3.3"
entities:
  - platform: light
    friendly_name: overall_power
    id: 20
  - platform: light
    friendly_name: laser_settings
    id: 102
    #color_mode: 21
    brightness: 22
    brightness_lower: 10
    brightness_upper: 1000
    #scene: 25
  - platform: light
    friendly_name: color_settings
    id: 103
    color_mode: 21
    color: 24
    brightness_upper: 1000

The entities are online in HA, but I notice the following:

I believe this has something to do with dps option 21. Using the cli I saw that when editing the color settings in the smar life app option 21 is set to color. When editing the laser setting option 21 is set to white.

How can I mimic this in localtuya config?

ultratoto14 commented 3 years ago

Maybe the best way is to configure only one configuration light with global on/off and two lights to control independently laser and color as :

host: !secret smart_star_projector_host
device_id: !secret smart_star_projector_id
local_key: !secret smart_star_projector_key
friendly_name: bedroom_kid_smart_star_projector
protocol_version: "3.3"
entities:
  - platform: light
    friendly_name: settings
    id: 20
    color_mode: 21
    color: 24
    brightness: 22
    brightness_lower: 10
    brightness_upper: 1000

  - platform: light
    friendly_name: laser
    id: 102
  - platform: light
    friendly_name: color
    id: 103

For rotation speed, you can use an input_number with a range 1-1000 and an automation that set the DP using the set_dp service when the value changed:

input_number:
  rotation_speed:
    name: Rotation Speed
    min: 10
    max: 1000
    step: 10

automation:
  trigger:
    platform: state
    entity_id: input_number.rotation_speed
  action:
  - data:
    service: localtuya.set_dp
      device_id: !secret smart_star_projector_id
      dp: 101
      value: {{ states('input_number.rotation_speed') }}

Something like this.

kireque commented 3 years ago

This work, but now I am unable to dim the laser. Default value is way too bright, so I want to be able to the color and the laser.

DP brightness is used for both laser and color, depending on DP 21. If DP 21 equals white, brightness is applied to laser. If DP 21 equals color then the brightness is applied to the colors.

ultratoto14 commented 3 years ago

If it works like other tuya devices, the brightness is encoded in the color value. You device have color and white in the same device. So it means that to change the laser brightness, you will need to pick the white center in the color picker in HA, this will switch your device to white mode. Then, changing the brightness will do on the laser. If you want to change then the color, choose the color, then change the brightness.

kireque commented 3 years ago

I tried your method but that does nog seems to work. But I have a workable situation now. If I turn on the star projector, I first setup the laser, then the colors.

Works for me. Thanks for your support!

ultratoto14 commented 3 years ago

Ok no pb.

buschtoens commented 2 years ago

Thanks a lot for this thread! It has been tremendously helpful in setting up my star projector.

I found the purpose of the previously unknown DP 26:

I also discovered a hack that allows me to control the rotation speed "more directly", by treating its DP 101 as a pseudo-light with brightness.

localtuya Configuration

This is the configuration I'm currently using:

# https://github.com/rospogrigio/localtuya/issues/297
host: nebula.<redacted>
device_id: <redacted>
local_key: <redacted>
friendly_name: Living Room Nebula
protocol_version: "3.3"
entities:
  # Overall On / Off Switch & Rotation.
  - platform: light
    friendly_name: Rotation
    id: 20 # Overall On / Off Switch
    brightness: 101 # Hack: Expose rotation speed as brightness.
    brightness_lower: 10
    brightness_upper: 1000

  # Overall On / Off Switch.
  # - platform: light
  #   friendly_name: Power
  #   id: 20

  # Rotation.
  # - platform: sensor
  #   friendly_name: Rotation
  #   id: 101
  #   scaling: 0.1

  # Stars: Green Laser.
  - platform: light
    friendly_name: Stars
    id: 102 # on / off
    brightness: 22
    brightness_lower: 10
    brightness_upper: 1000

  # Nebula: RGB Projector.
  - platform: light
    friendly_name: Nebula
    id: 103 # on / off
    color_mode:
      21
      # white: if saturation == 0x0000
      # colour: if saturation >= 0x0001    (British English `colour`!)
      # scene: read scene config from DP `scene: 25`
      # music: apparently not available on this device (no mic)
    color:
      24 # 12 byte HSV
      # hue:        0x0000 - 0x0168  [360]
      # saturation: 0x0000 - 0x03e8 [1000],
      #             all RGB combined (white) - selected hue only
      # value:      0x0000 - 0x03e8 [1000]
    scene:
      25 # 2 bytes + n * 26 bytes
      # First 2 bytes:
      #
      # scene_num: 0x00 - 0x08
      #   0x00: ???
      #   0x01: ???
      #   0x02: ???
      #   0x03: ???
      #   0x04: Scene 1, default name "Sleeping"
      #   0x05: Scene 2, default name "Romantic"
      #   0x06: Scene 3, default name "Party"
      #   0x07: Scene 4, default name "Relaxing"
      #
      # Followed by 1 - 8 groups of 26 bytes each:
      # Each group encodes encodes a keyframe from `scene_units`.
      #
      # Group bytes 0 - 5: keyframe transition behavior
      #  +0, 2 | unit_switch_duration:   x00 - 0x64 [100], seconds
      #  +2, 2 | unit_gradient_duration: x00 - 0x64 [100], seconds
      #  +4, 2 | unit_change_mode:
      #        |   0x00: static
      #        |   0x01: jump
      #        |   0x02: gradient
      #
      # Group bytes 6 - 17: nebula color & brightness, like DP `color: 24`
      #  +6, 4 | hue:         0x0000 - 0x0168  [360]
      # +10, 4 | saturation:  0x0000 - 0x03e8 [1000]
      # +14, 4 | value:       0x0000 - 0x03e8 [1000]
      #
      # Group bytes 18 - 25: unknown
      # +18, 4 | brightness:  0x0000 - 0x03e8 [1000]
      #        |    Functionality unknown. It's NOT `brightness: 22`.
      # +22, 4 | temperature: 0x0000 - 0x03e8 [1000]
      #        |   Functionality unknown.
      #
      # Example: Scene 1, "Sleeping", 2 frames
      #
      # SN  SD GD CM     H    S    V  Brig Temp
      # 04  46 46 02  0078 03e8 03e8  0000 0000
      #     46 46 02  0078 03e8 000a  0000 0000
      #
      # Example: Scene 4, "Relaxing", 6 frames
      #
      # SN  SD GD CM     H    S    V  Brig Temp
      # 07  46 46 02  0000 03e8 03e8  0000 0000
      #     46 46 02  0078 03e8 03e8  0000 0000
      #     46 46 02  00f0 03e8 03e8  0000 0000
      #     46 46 02  003d 03e8 03e8  0000 0000
      #     46 46 02  00ae 03e8 03e8  0000 0000
      #     46 46 02  0113 03e8 03e8  0000 0000

Lovelace UI Integration

And I integrated the device into lovelace like so:

Standalone Card
```yaml type: entities title: Nebula show_header_toggle: true entities: - type: custom:slider-entity-row icon: mdi:rotate-right entity: light.living_room_nebula_rotation min: 1 hide_when_off: true toggle: false - entity: light.living_room_nebula_laser type: custom:slider-entity-row toggle: true hide_when_off: true - entity: light.living_room_nebula_projector type: custom:slider-entity-row toggle: true hide_when_off: true - type: custom:light-entity-card entity: light.living_room_nebula_projector effects_list: false hide_header: true shorten_cards: true child_card: true brightness: false ```
Embedded Expandable Group in Card
```yaml type: entities title: Couch show_header_toggle: false entities: # ... - type: section - type: custom:fold-entity-row clickable: true head: entity: light.living_room_nebula_rotation icon: mdi:flare name: Nebula entities: - type: custom:slider-entity-row icon: mdi:rotate-right entity: light.living_room_nebula_rotation min: 1 hide_when_off: true toggle: false - entity: light.living_room_nebula_laser type: custom:slider-entity-row toggle: true hide_when_off: true - entity: light.living_room_nebula_projector type: custom:slider-entity-row toggle: true hide_when_off: true - type: custom:light-entity-card entity: light.living_room_nebula_projector effects_list: false hide_header: true shorten_cards: true child_card: true brightness: false ```
pergolafabio commented 1 year ago

Hi, thnx for info, alsu purchased 2 projectors for my kids... I see you created a lovelace card, nice

But how is it possible to add all those 3 attributes in a normal light entity? So when you click on more info, they are all avainble? now they are 3 seperate lights

thnx

pergolafabio commented 1 year ago

Hey @kireque , I do have same issues... I can't control the color sometimes, can't turn it on.. I need to turn it on with smart life app, then it works again...

I have the feeling after adjusting color in HA, it gets unresponsive.... Already using the config posted a few posts back... Do you have a working solution?

kireque commented 1 year ago

Hi @pergolafabio,

In the end I modified my smart star projector by replacing the chip with an esp. Created a tutorial how I did it: https://github.com/kireque/esphome_nebula_light

So I am not using this integration anymore.

pergolafabio commented 1 year ago

Gzeat, ,thnx for tutorial, but I'm not a solder specialist, gonna skip this one and keep it safe :-)

pergolafabio commented 11 months ago

hey @kireque , is it supported now?

kireque commented 11 months ago

Hey @pergolafabio I am not sure. Was closing old and stale issues that were on my name

pergolafabio commented 11 months ago

ah ok , well dont think its integrated yet, maybe leave it open? :-)

kireque commented 11 months ago

Reopend the case. Hopefully for you it wil be implemented soon :)

pergolafabio commented 11 months ago

yeah, i now do it manually, alltough its not perfect