Trigger based on Light brightness change

Is there any way I can use brightness change from a dimmable switch(light.basement) as trigger?

In trigger option/state it only detects on or off. How do I detect change in brightness.

If there a way/link where I can check all possible events/states a device can have?

Harry

Edit: final working code snippet is here: https://community.home-assistant.io/t/trigger-based-on-light-brightness-change/267209/36?u=harrypatel04.
Thank you @123, @Burningstone, @CO_4X4

Trigger on a change of the attribute brightness of the light.

E.g.

trigger:
  platform: state
  entity_id: light.basement
  attribute: brightness

This is in YAML right? Not in UI.

I have just started HA and not very good in YAML.
In any case, how do I read the value? trigger.XXXX?

The assumption you are proficient in YAML is because you tagged your post with “Blueprints”. There’s no way anyone can create a Blueprint without knowledge of YAML.

However, your question has nothing to do with Blueprints.

I apologize for choosing wrong category. I’ll try to change it.

You have the state and you have the attributes, the on/off issue you are referring to is the state of the device, where the brightness is an attribute.

You can find all the attributes in the online docs (i.e., for lights ).

The example you got was YAML, but the user interface is just a shortcut to create that YAML and nobody wants to screenshot all the examples :). So to translate what was provided in the UI:

1 Like

What do you want the automation to do after it detects a light has changed brightness level?

@CO_4X4

For some reason Attribute only shows 2 option in this light. Friendly Name and Supported feature.
Drop down has only these two options.

You can type it in by hand.

@123
I’m migrating away from Smartthings. I have a Location status in Smartthings( Home, Away, Night) which I’m trying to map via a simulated dimmer bulb.

I have created webcore routes in ST that changes brighness of the dimmer bulb based on it’s location state. I’m trying to read that value in HA and then I’ll use it in different automation to perform different task based on this value.

How do I read that value? trigger.XX or state.lightname.brighness??
Sorry for dumb questions.

You’ll have to cozy up to YAML. It feels a bit daunting at first but it’s not too bad once you get the hang of it. To answer your question you would have something like this:

"{{state_attr('light.basement_bar','brightness')}}"

If you want a simulated dimmer bulb you’ll need a template light or switch, and you can use the code above to set the values of it accordingly.

Here is an example from my own system where I synchronize the state of a “dummy” light to the status of another light and use a single light entity to control two other lights. While the outcome is a bit different, it is similar enough that you can use it as a baseline to draft your own.

couch_group:
  friendly_name: "Couch Group"
  unique_id: couch_combined_light
  level_template: "{{ state_attr('light.couch_floor_hue', 'brightness')|int }}"
  value_template: "{{ is_state('light.couch_floor_hue', 'on') }}"
  turn_on:
    - service: light.turn_on
      entity_id: light.couch_floor_hue
    - service: light.turn_on
      entity_id: light.couch_table_hue
  turn_off:
    - service: light.turn_off
      entity_id: light.couch_floor_hue
    - service: light.turn_off
      entity_id: light.couch_table_hue
  set_level:
    - service: light.turn_on
      data_template:
        brightness: "{{ brightness }}"
        entity_id: light.couch_floor_hue
    - service: light.turn_on
      data_template:
        brightness: "{{ brightness }}"
        entity_id: light.couch_table_hue

1 Like

Thank you.

As I have mentioned, I’m migrating away from ST and wanted to move gradually to not overwhelm myself. So I have paired ST with HA and I can see all the physical devices in HA.

ST has a logical/virtual entity named Location. Home/Away/Night,etc. I’m just trying to sync that status somehow with something here in HA. So far not doing good :slight_smile:

I am thinking of creating 3 boolean flags and set/reset them based on Brighness value which will have some fixed value based on location status in ST. May be there’s some other simple way, but as I said I’m just a week old. Let me read more in forum and online docs.
Thank you.

You can go into the Developer section of HA and pull up the states for the “source entity”, that will tell you the state and the attributes, then you can use a modification of my above sample to bring that data into your automation or into another template entity.

This is the chapter you need to digest:

Specifically the section on the Trigger State Object. That’s what lets you use the value, that caused the trigger to occur, within the automation’ action.

If I do manually create automation in YAML, should I add them in automations.yaml or I should keep this file for UI automations only.

Can I have another file and create manual/YAML automations in that file?
I tried adding automation line in configurations file twice and it gave me error.

automation: !include automations.yaml
automation: !include myautomations.yaml

2|hass  | 2021-01-11 16:57:12 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /data/data/com.termux/files/home/.homeassistant/configuration.yaml contains duplicate key "automation". Check lines 11 and 12

You can’t have two automation sections like that, your YAML will throw an error. From the HA docs on automation it tells you exactly how to either use the YAML editor in automations or add manual automatons in the configuration.yaml file.

Change the second line to this:

automation yaml: !include myautomations.yaml

Thank you, this worked.