Been puzzling on this for a few days, can’t get my test case working.
The test case is someone walks down hall, triggers motion sensor, automation turns on hall dimmer to 20% brightness. After 40 seconds delay turn off the hall dimmer if no motion. So my automation is set to restart when motion is detected within those 40 seconds.
Now what I want to do is, NOT execute the automation if someone raised the brightness. For example I am looking for something in the hall closet and need a bright light. I know I need a condition, but I’m failing getting everything correct. Is my problem code or understanding of devices and states maybe? My attempts to code have all been trying to detect if the dimmer brightness is > 20% which is the value I use to automate in the above code, where I have a helper value.
Here is the condition I have currently. It always fails. My thinking is the last brightness_pct value I set was 20, so that value is still in the machine state. But now I am wondering, if the last thing executed was to turn the dimmer off, is that brightness_pct attribute still valid? This is where I need some advise. Does my condition need to test if the dimmer is ‘on’ AND brightness_pct == 20 or do I have a coding error??
Where are you including that condition? It seems to me that you’d want it in the action sequence, before the turn_off call, and I’m not sure why it wouldn’t work there.
I agree with what r-j-taylor said. Also, once you get this working, you might as well use input_number.front_hall_dimmer_level in your condition instead of the hardcoded 20, lest the condition break should you change the input number value.
Absolutely would replace hard coded value, I never leave things hard coded, drives me crazy… but I’ve been playing with this so long… for testing and simplifying… I hard coded
Not really… and this is what makes this a thinker… .
The actions are to turn on the dimmer setting to 20%, then waiting 40 seconds and turn off the dimmer. This is use case is passing down the hall… I don’t have to touch switches, lights come on dim, and og off behind me.
Putting a condition before turning off the dimmer… on a restart of the automation will allow it to fall through, turn on the dimmer (already on), set the brightness_pct to 20%, Thereby overwriting the value set by someone who raised the dimmer brightness. That’s the trick right there and I’ve been there and done that
So I remain resolute that the solution has to be in the conditions before any action is executed… I don’t want the brightness to change and I don’t want automation to shut off the dimmer either… if someone manually turned up the lights, for example to look for something in the hall closet, then let them turn them off too.
Add a condition to the automation to not run if the light is already on and replace the delay in the sequence with a wait_for_trigger to wait until the motion sensor’s state is ‘off’ for 40 seconds?
you could test that the brightness_pct attribute is defined then check if it is equal to you’re input_number value:
condition:
- condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: or
conditions:
- condition: template
value_template: "{{ state_attr('light.front_hall_light_dimmer', 'brightness_pct') is not defined }}"
- condition: template
value_template: "{{ state_attr('light.front_hall_light_dimmer', 'brightness_pct') is defined and state_attr('light.front_hall_light_dimmer', 'brightness_pct') | int == states('input_number.whatever_your_entity_is') | int }}"
if it’s false (the light is not on or if the light is on and the brightness equals the dimmer input value then run the automation. otherwise don’t run it.
I like Finity’s idea. I did test this, but did not get the expected results. So I took a break and tried thinking about this fresh. Today’s thought was let try and learn how to see exactly what’ going on with the values. Looking the trace screens and step details brightness_pct is never defined. These screen don’t show values though. So I took some time to look and learn a little about the Developers Tools and ended up in the template editor to look at values.
What I found is brightness_pct is not defined… Or I haven’t figured out how to access that value correctly yet. I can see brightness which is a value between 0 and 255. So I played around trying some different things, and watching the template. brightness_pct never shows a value and brightness always shows a value 1 less than the value set.
I guess I can use brightness attribute and code around the 1 number difference… or try to figure out what I doing wrong that I can set brightness_pct… but not access it to view or use to test in my logic.
I thought that lights could either use brightness or brightness_pct as desired in each light platform implementation.
the code for the light integration has the “attr_brightness_pct” listed so I take that to be it is a valid attribute as long as the platform implements it. But of course I could be reading it wrong.
But I don’t see a purpose to support brightness_pct if we already have brightness and if brightness_pct isn’t a valid/useful attribute. Why waste resources on it?
I know one person has already filed an issue on one of my custom button rows about the light not working with it and I think we narrowed it down to the light using brightness_pct instead of brightness, which is the service data the plugin uses.