Caseta Pico Remote to Zigbee2MQTT light

I previously posted a blueprint for Pico to ZHA lights. I recently transitioned to Z2M / Zigbee2MQTT for my lights, and I wanted to write a similar blueprint for Zigbee2MQTT as I wanted smooth dimming for those lights as well. The blueprint includes a cluster command to stop dimming, which is why it needs to be implementation-dependent. The lights will receive a start dimming command with the duration specified and then a stop dimming command when the button is released.

The original blueprint used stephack’s blueprint for pico remotes and then this blueprint builds on top of that. Zigbee2MQTT is a little easier to use as it uses the same integration for sending cluster commands to Zigbee groups and individual lights.

You may notice a slight pop effect at the end of a dimming sequence with a Zigbee group as the integration waits for a second before reading in the brightness and setting all of the bulbs to the same level. By default, the middle button doesn’t do anything, but it is exposed in case you want to implement something for it. I like to use it to toggle a lamp or turn Christmas tree lights on and off or set a scene like movie theater mode.

As mentioned in the previous post, I still have the modified joshcarter’s 3D printed Pico wall mount for a more solid feel, which I posted here.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Z2M - Pico Config
  description: "This is for the 5 button picos that have the following model:\n\n
    PJ2-3BRL-GXX-X01 (Pico3ButtonRaiseLower)\n\nSelect the pico and light to use below"
  domain: automation
  input:
    pico_remote:
      name: Pico Remote
      description: 'Select the pico remote to configure:'
      selector:
        device:
          model: PJ2-3BRL-GXX-X01 (Pico3ButtonRaiseLower)
          multiple: false
    light:
      name: Zigbee Light
      description: "Select the light to control.\nIf using a group, select the main light for matching brightness:"
      selector:
        entity:
          multiple: false
    z2m_friendly_name:
      name: Z2M Friendly Name
      description: "Friendly name in Zigbee2MQTT - Can be group or individual light"
      default: []
    dimming_speed:
      name: Dimming Speed
      description: 'Input the dimming speed to go from 0 to 100%'
      default: 5
    turn_on_speed:
      name: Turn On Speed
      description: 'Input the time to turn on the light'
      default: 0
    turn_off_speed:
      name: Turn Off Speed
      description: 'Input the time to turn off the light'
      default: 2
    auto_mode:
      name: Automation Mode
      description: Mode that automation runs in (single,  restart, queued, parallel).
      default: restart
      selector:
        select:
          options:
          - single
          - restart
          - queued
          - parallel
          multiple: false
          custom_value: false
    mode_max:
      name: Mode Max (ignored by Single and Restart Modes)
      description: Maximum number of runs that can be executed or queued at a time.
      default: 10
      selector:
        number:
          min: 1.0
          max: 15.0
          mode: slider
          step: 1.0
    middle_stop:
      name: Middle (Fav) Button Pressed
      description: Execute when MIDDLE button is PRESSED
      default: []
      selector:
        action: {}
    middle_stop_release:
      name: Middle (Fav) Button Released
      description: Execute when MIDDLE button is RELEASED
      default: []
      selector:
        action: {}
variables:
  light_entity: !input light
  dimming_speed: !input dimming_speed
  z2m_friendly_name: !input z2m_friendly_name
  turn_off_speed: !input turn_off_speed
trigger:
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: press
  subtype: 'on'
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: press
  subtype: raise
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: press
  subtype: stop
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: press
  subtype: lower
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: press
  subtype: 'off'
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: release
  subtype: 'on'
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: release
  subtype: raise
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: release
  subtype: stop
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: release
  subtype: lower
- platform: device
  device_id: !input pico_remote
  domain: lutron_caseta
  type: release
  subtype: 'off'
condition: []
action:
- choose:
  - conditions: '{{ trigger.event.data.action == "press" }}'
    sequence:
    - choose:
      - conditions: '{{ trigger.event.data.button_number == 5 }}' #up_raise
        sequence: 
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/{{z2m_friendly_name}}/set
              payload: |-
                {
                  "command": {
                    "cluster": 8,
                    "command": 3,
                    "payload": {}
                    }
                }
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/{{z2m_friendly_name}}/get
              payload: |-
                {"brightness": ""}
          - service: light.turn_on
            data:
              brightness: 255
              transition: >-
                {{(((255-(state_attr(light_entity, 'brightness') | int(0)))/255)*(dimming_speed|float(5)-0.1))+0.1}}
            target:
              entity_id: >
                {{light_entity}}
      - conditions: '{{ trigger.event.data.button_number == 3 }}'
        sequence: !input middle_stop
      - conditions: '{{ trigger.event.data.button_number == 6 }}' #down_lower
        sequence: 
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/{{z2m_friendly_name}}/set
              payload: |-
                {
                  "command": {
                    "cluster": 8,
                    "command": 3,
                    "payload": {}
                    }
                }
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/{{z2m_friendly_name}}/get
              payload: |-
                {"brightness": ""}
          - if:
              - condition: not
                conditions: >
                  {{is_state(light_entity, 'off')}}
            then:
              - service: light.turn_on
                data:
                  brightness: 4
                  transition: >-
                    {{(((state_attr(light_entity, 'brightness') | int(0))/255)*(dimming_speed|float(5)-0.1))+0.1}}
                target:
                  entity_id: >
                    {{light_entity}}
  - conditions: '{{ trigger.event.data.action == "release" }}'
    sequence:
    - choose:
      - conditions: '{{ trigger.event.data.button_number == 2 }}' # top_on_release
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/{{z2m_friendly_name}}/set
              payload: |-
                {
                  "command": {
                    "cluster": 8,
                    "command": 3,
                    "payload": {}
                    }
                }
          - service: light.turn_on
            data:
              brightness: 255
              transition: !input turn_on_speed
            target:
              entity_id: >
                {{light_entity}}
      - conditions: '{{ trigger.event.data.button_number == 3 }}'
        sequence: !input middle_stop_release
      - conditions: '{{ trigger.event.data.button_number == 6 or trigger.event.data.button_number == 5 }}' # down_lower_release or up_raise_release
        sequence:
          - if:
              - alias: "Test for off"
                condition: template
                value_template: >
                  {{is_state(light_entity, 'on')}}
            then:
              - service: mqtt.publish
                data:
                  topic: zigbee2mqtt/{{z2m_friendly_name}}/set
                  payload: |-
                    {
                      "command": {
                        "cluster": 8,
                        "command": 3,
                        "payload": {}
                        }
                    }
              - service: mqtt.publish
                data:
                  topic: zigbee2mqtt/{{z2m_friendly_name}}/get
                  payload: |-
                    {"brightness": ""}
                  qos: "2"
              - delay:
                  seconds: 1
              - service: light.turn_on
                data:
                  brightness: >
                    {{state_attr(light_entity, 'brightness')}}
                target:
                  entity_id: >
                    {{light_entity}}
      - conditions: '{{ trigger.event.data.button_number == 4 }}' # bottom_off_release
        sequence:
          - service: light.turn_off
            data:
              transition: '{{ turn_off_speed - 0.2 }}'
            target:
              entity_id: >
                {{light_entity}}
  default: []
mode: !input auto_mode
max: !input mode_max