Lutron Caseta Diva Remember Brightness - How To

Hey all, this is my first post so feel free to let me know if there are ways to make it better.

I want my Lutron Caseta Diva switch to remember its brightness level just like a philips hue bulb while still letting the physical switch work just as before.
The way I did this is by making a template light which you control from your phone, and everytime you turn on the templated light it sets the correct brightness to the real light.

Here is the solution I came up with.

  1. Name the physical Lutron switch something different than what you want to use. I named my switch: “nicks_bedroom_main_lights_lutron_switch”
    Later we will create a template light with the proper name of the device you want to control.

  2. Install Home-Assistant-Variables: GitHub - snarky-snark/home-assistant-variables: A custom Home Assistant component for declaring and setting generic variable entities dynamically.

  3. Add variable to configuration.yaml file:

var:
  nicks_bedroom_main_lights_helper_brightness:
    friendly_name: Nicks Bedroom Main Lights Helper Brightness
    initial_value: 0
    unique_id: "nicks_bedroom_main_lights_helper_brightness"
  1. Next make a template light. I have my templates set up to be individual files in a folder. Here is my “nicks_bedroom_lutron_helper.yaml” inside my template folder.
- light:
    - name: "Nicks Bedroom Main Lights"
      unique_id: "nicks_bedroom_main_lights_helper_template"
      level: "{{ state_attr('light.nicks_bedroom_main_lights_lutron_switch', 'brightness') |int }}"
      state: "{{ state_attr('light.nicks_bedroom_main_lights_lutron_switch', 'brightness') |int > 0 }}"
      turn_on:
        action: light.turn_on
        target:
          entity_id: light.nicks_bedroom_main_lights_lutron_switch
        data:
          brightness: "{{ states.var.nicks_bedroom_main_lights_helper_brightness.state }}"
      turn_off:
        action: light.turn_off
        target:
          entity_id: light.nicks_bedroom_main_lights_lutron_switch
      set_level:
        - action: light.turn_on
          target:
            entity_id: light.nicks_bedroom_main_lights_lutron_switch
          data:
            brightness: "{{ brightness }}"
        - action: var.set
          data:
            entity_id:
              - var.nicks_bedroom_main_lights_helper_brightness
            value: "{{ brightness }}"

  1. Finally, we make an automation that updates the brightness variable whenever someone physically adjusts the brightness on the switch.
    To add this, in HA go to settings/automations and create a new automation. In the upper right hand corner click “Edit in Yaml”. Paste this code:
alias: nicks_bedroom_main_lights_helper_automation
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.nicks_bedroom_main_lights_lutron_switch
    attribute: brightness
    id: brightness
conditions: []
actions:
  - action: var.set
    metadata: {}
    data:
      entity_id: var.nicks_bedroom_main_lights_helper_brightness
      value: "{{ state_attr('light.nicks_bedroom_main_lights', 'brightness') |int }} "
    enabled: true
mode: single

Now in HA go to developer tools, make sure to check your configuration and then reboot HA (or just reload the yaml config.)

Hopefully all is working. I named my template light “Nicks Bedroom Main Lights” and use that exclusively as the entity to control my physical light.

Thanks!