Help with light automation - trigger on brightness_pct change while already on

Also posted on reddit, posting here for parity.

I’m trying to figure out how to trigger an automation when a dimmer light changes from any non-zero value for ‘brightness_pct’ to any value.

I have all the normal light automations working; trigger when motion detected, turn it off 5m after last motion, different brightnesses based on luminance and sun positioning, etc.

I’m using an ‘input_boolean’ to track whether a light was engaged via automation (true) or manually so that the auto-off automation can check if it should fire or not. The desire is if a light was turned on manually it shouldn’t auto off so quickly.

I have it working so that if a light triggers via automation, and you turn it off manually, it resets the input_boolean to false, but I need to find a way to also set the input_boolean to false if you change the brightness_pct.

Current Automation example: https://pastebin.com/vVDwn2i0

TL;DR trigger automation when brightness_pct changes from any non-zero to anything. Something like from: 'on' to: 'on', but not from: 'off' to: 'on'.

TIA

The easiest way I can think of would be to break out the brightness attribute using a template sensor.
Trigger on any change of state of the sensor.
Include a condition that the trigger from state be greater than 0.

1 Like

I’ll look into that, thank you!

trigger:
  platform: state
  entity_id: light.LIGHT
condition:
  condition: template
  value_template: >
    {{ trigger.from_state is not none and
       trigger.from_state.state == 'on' and
       trigger.from_state.attributes.brightness > 0 and
       trigger.to_state is not none and
       trigger.to_state.state == 'on' }}
5 Likes

That looks like it may do the trick. I will test it and mark as solution if it does. Thank you!

1 Like

How are you changing the brightness ?
I ask because I have an input number that gives the brightness of a group of my bulbs.
When the input number changes state (easy state change) it then sets the group to that brightness.
This is easy to put in the front end and you would not have to configure a sensor to do it.
You also have your trigger for whatever you are doing (if that’s changing the level of other bulbs, then your work is done.

How are you changing the brightness ?

Manually and via motion

it then sets the group to that brightness

This is a cool idea that I may try out. thanks!

This worked, thanks!

I would marry you just for your templates
:heart_eyes::heart_eyes:

Actually as I think about it some more I think you can remove this line:

       trigger.from_state.attributes.brightness > 0 and

If the brightness was zero it would have been off, and since it already tests that it was on, I think this is redundant.