Sunricher SG2858A blueprint

Hi,

This blueprint is for controlling a light with the Sunricher SG2858A remote. The following is supported:

  • set color
  • set light temp
  • on / off
  • dim up/down (short press = step, long press = move)
  • buttons S1 to S5 can either execute custom scripts, or activate a scene (configurable)
  • all three endpoints (buttons 1, 2, 3) of the remote are supported, you have to instantiate this blueprint once for each endpoint

The only thing that is not working currently is the Home(6) button, which does not trigger a zha event currently. Needs to investigate on this (probably needs a quirk).

blueprint:
  name: Handle sunricher sg2858a events
  description: >
    Runs the light commands given the received events.
    The device supports 3 groups, and sends commands for all the selected
    groups.
    The following commands are supported for each endpoint:
    
    * recall (scene mode), 1 to 5
    
    * dim (step) down / up 
    
    * dim up/down with stop
    
    * move to color
    
    * move to temp
    
    * "on" and "off" (separate commands)
    
  domain: automation
  input:
    remote:
      name: Sunricher remote
      description: The remote device to use for the automation
      selector:
        device:
          entity:
            - integration: zha
          filter:
            - manufacturer: Sunricher
              integration: zha
              model: ZG2858A
#      default: 
#        device_id: 17cd50f04cd5e8c747b276faf4b59eac
    target_light:
      name: Light to control
      description: The light to control with the remote
      default: {}
      selector:
        target:
          entity:
            - domain: light
    source_endpoint:
      name: Group (1, 2 or 3)
      description: The remote group this script uses (1, 2, 3 on the remote)
      default: 1
      selector:
        number:
          min: 1
          max: 3
          step: 1
    scene_recall_script_1:
      name: Script or scene to call for scene recall 1
      default: null
      selector:
        entity:
          filter:
            domain: 
              - script
              - scene
    scene_recall_script_2:
      name: Script or scene to call for scene recall 2
      default: null
      selector:
        entity:
          filter:
            domain: 
              - script
              - scene
    scene_recall_script_3:
      name: Script or scene to call for scene recall 3
      default: null
      selector:
        entity:
          filter:
            domain: 
              - script
              - scene
    scene_recall_script_4:
      name: Script or scene to call for scene recall 4
      default: null
      selector:
        entity:
          filter:
            domain: 
              - script
              - scene
    scene_recall_script_5:
      name: Script or scene to call for scene recall 5
      default: null
      selector:
        entity:
          filter:
            domain: 
              - script
              - scene
trigger:
  - platform: event
    id: turn_off
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "off"
      args: []
      params: {}
  - platform: event
    id: turn_on
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "on"
      args: []
      params: {}
  - platform: event
    id: dim_up
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "step_with_on_off"
      args: [0, 32, 0]
      params:
        step_mode: 0
        step_size: 32
        transition_time: 0
  - platform: event
    id: dim_down
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "step_with_on_off"
      args: [1, 32, 0]
      params:
        step_mode: 1
        step_size: 32
        transition_time: 0
  - platform: event
    id: move_to_color
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "move_to_color"
#       params:
#         color_x: 15859
#         color_y: 33357
#         transition_time: 0
#         options_mask: 0
#         options_override: 0    
  - platform: event
    id: move_to_temp
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "move_to_color_temp"
#      params:
#        color_temp_mireds: 440
#        transition_time: 0
#        options_mask: 0
#        options_override: 0
  - platform: event
    id: move_up_with_on_off
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "move_with_on_off"
      params:
        move_mode: 0 #  1 <-- down, 0 for up
  - platform: event
    id: move_down_with_on_off
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "move_with_on_off"
      params:
        move_mode: 1 #  1 <-- down, 0 for up
  - platform: event
    id: stop_with_on_off
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "stop_with_on_off"
  - platform: event
    id: scene_recall
    event_type: zha_event
    event_data:
      device_id: !input remote
      endpoint_id: !input source_endpoint
      command: "recall"
#     params:
#       group_id: 0
#       scene_id: 5
variables:
  scene_recall_script_1_v: !input scene_recall_script_1
  scene_recall_script_2_v: !input scene_recall_script_2
  scene_recall_script_3_v: !input scene_recall_script_3
  scene_recall_script_4_v: !input scene_recall_script_4
  scene_recall_script_5_v: !input scene_recall_script_5
  
mode: restart # restart is very important, the move with stop handling
              # relies on this

action:
  - choose:
    - conditions:
      - condition: trigger
        id: move_to_color
      sequence:
        - service: light.turn_on
          target: !input target_light
          data:
            xy_color:
              - '{{ trigger.event.data.params.color_x| int / 65535 }}'
              - '{{ trigger.event.data.params.color_y | int / 65535 }}'
    - conditions:
      - condition: trigger
        id: dim_up
      sequence:
        - service: light.turn_on
          target: !input target_light
          data:
            brightness_step_pct: 8
    - conditions:
      - condition: trigger
        id: dim_down
      sequence:
        - service: light.turn_on
          target: !input target_light
          data:
            brightness_step_pct: -8
    - conditions:
      - condition: trigger
        id: turn_on
      sequence:
        - service: light.turn_on
          target: !input target_light
    - conditions:
      - condition: trigger
        id: turn_off
      sequence:
        - service: light.turn_off
          target: !input target_light
    - conditions:
      - condition: trigger
        id: move_to_temp
      sequence:
        - service: light.turn_on
          target: !input target_light
          data:
            color_temp: '{{ (trigger.event.data.params.color_temp_mireds |int) + ((trigger.event.data.params.color_temp_mireds | int)- 314.5) / 5 }}'
    - conditions:
      - condition: trigger
        id: move_up_with_on_off
      sequence:
        - repeat: # repeat inconditionnally. Script is interrupted by another instance by stop event
            count: 13
            sequence:
              - service: light.turn_on
                data:
                  brightness_step_pct: 8
                target: !input target_light
              - delay:
                  hours: 0
                  minutes: 0
                  seconds: 0
                  milliseconds: 300
    - conditions:
      - condition: trigger
        id: move_down_with_on_off
      sequence:
        - repeat:
            count: 13
            sequence:
              - service: light.turn_on
                data:
                  brightness_step_pct: -8
                target: !input target_light
              - delay:
                  hours: 0
                  minutes: 0
                  seconds: 0
                  milliseconds: 300

# scene recall
    - conditions:
      - condition: trigger
        id: scene_recall
      - '{{ trigger.event.data.params.scene_id == 1 }}'
      sequence:
          - if:
            - '{{ scene_recall_script_1_v != None }}'
            then:
              - service: homeassistant.turn_on
                target:
                  entity_id: '{{ scene_recall_script_1_v }}'

    - conditions:
      - condition: trigger
        id: scene_recall
      - '{{ trigger.event.data.params.scene_id == 2 }}'
      sequence:
          - if:
            - '{{ scene_recall_script_2_v != None }}'
            then:
              - service: homeassistant.turn_on
                target:
                  entity_id: '{{ scene_recall_script_2_v }}'

    - conditions:
      - condition: trigger
        id: scene_recall
      - '{{ trigger.event.data.params.scene_id == 3 }}'
      sequence:
          - if:
            - '{{ scene_recall_script_3_v != None }}'
            then:
              - service: homeassistant.turn_on
                target:
                  entity_id: '{{ scene_recall_script_3_v }}'

    - conditions:
      - condition: trigger
        id: scene_recall
      - '{{ trigger.event.data.params.scene_id == 4 }}'
      sequence:
          - if:
            - '{{ scene_recall_script_4_v != None }}'
            then:
              - service: homeassistant.turn_on
                target:
                  entity_id: '{{ scene_recall_script_4_v }}'

    - conditions:
      - condition: trigger
        id: scene_recall
      - '{{ trigger.event.data.params.scene_id == 5 }}'
      sequence:
          - if:
            - '{{ scene_recall_script_5_v != None }}'
            then:
              - service: homeassistant.turn_on
                target:
                  entity_id: '{{ scene_recall_script_5_v }}'

Hope this will be useful for others.

2 Likes