Hello,
I have a lot of lutron caseta in-wall dimmers and i was surprised to find that HA as it is cant remember the last dimmer value of the dimmer… every time you turn it off and on it resets to 100%. I have found a solution that is working for me so i wanted to share it in case others hit the same issue.
This is not the cleanest solution but it works. In a nutshell i am using an integration that enables variables in home assistant. Im sure you could change this to just some some sort of built-in input function but i went the variables route.
The idea is that i have a script that is called each time a button-cards pushed… again you could use a different trigger. When that button is pushed, the script checks to see if the light is on, if it is on, then it first saves the dimmer value in a variable named after the dimmer ‘light’ element itself and then it turns off the light (service call). If the light was off, then it turns the light on using that dimmer value that is stored in the variable.
This solution does require you to setup variables for each dimmer you have in your configuration.yaml file… so there is a bit of work there. I also still want to somehome templatize the name of the variable in the script which is what i need to do next. So for example, if i have a light called light.upstairs then i would use a variable called var.upstairs_level and in the script be able to derive that variable name from the entity_id of the light itself. Still need to do that. However i wanted to share what i have working so far.
FIrst off im using this integration for variables. You can install it thru HACS.
I will then show an example for a single dimmer.
In the configuration.yaml file i define a variable for the dimmer. You’d need one of these for each of your variables. Too bad the integration didnt allow for dynamic creation… maybe down the road
var:
office_main_lights_level:
initial_value: 100
icon: mdi:light
Then i have an action that could be tied to a switch or a button or an automation etc. I have it as a tap-action inside a button-card. Im dynamically sending the entity id.
tap_action:
action: call-service
service: script.lutron_test
service_data:
dimmer: >
[[[ return variables.entity_id ]]]
Then here is my script:
lutron_test:
fields:
dimmer:
description: Lutron dimmer to store and restore dimming value
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ is_state( dimmer, "off") }}'
sequence:
- service: light.turn_on
data:
brightness: "{{ states('var.office_main_lights_level') }}"
target:
entity_id: '{{ dimmer }}'
default:
- service: var.set
target:
entity_id: var.tom_s_office_main_lights_level
data:
value: "{{ state_attr(dimmer , 'brightness') }}"
- service: light.turn_off
data: {}
target:
entity_id: '{{ dimmer }}'
Again, i want to provide a way to make the variable name a template so i dont have one script per dimmer but this seems to work as intended! Now my lights remember their dimmer values.
hope this helps someone else out there… feedback welcome… once i have the variable name template figured out ill post that too.