Automation turn off light after x amount of time

I want to create an automation that start only when i press button (virtual button) that set light diming at 5% and turn off after x amount of time.

i found something but it’s outdated i try to reproduce but no success.

any help it would be helpful like guide or yt videos.
Thank you.

You could use a https://www.home-assistant.io/integrations/timer/

  1. Push the button: Set the light to 5% and start the timer
  2. When the timer expires, turn off the light

You could also use a delay:

  1. Push the button: Set the light to 5%, delay X minutes, turn off the light

yes, i know how to create a timer , but i don’t know how to use on dash board with dimming :frowning:

this start the timer but how can i link the light and diming?

type: custom:mushroom-entity-card
tap_action:
  action: call-service
  service: timer.start
  target:
    entity_id: timer.timer
hold_action:
  action: more-info
double_tap_action:
  action: none
entity: timer.timer
  • When the timer starts, it sets the light’s brightness to 5%.
  • When the timer finishes, it sets the light’s brightness to 0%.
alias: example 
trigger:
  - id: '5'
    platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.your_timer
  - id: '0'
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.your_timer
action:
  - service: light.turn_on
    target:
      entity_id: light.your_light
    data:
      brightness_pct: "{{ trigger.id }}"

EDIT

Correction. Wrapped id values in quotes to ensure they are interpreted as strings.

2 Likes

Thank you @123 but can you explain now where to put this code, i know how to create helpers automation from UI and edit buttons from dashboard but this it’s new to me, as you can see i’m at newbie level.

  1. In the Automation Editor, create a new, blank automation.
  2. Switch to YAML mode (available in the overflow menu, three vertical dots, in the upper right hand corner).
  3. Delete whatever may already be displayed in the editor.
  4. Copy-paste the example I posted above into the editor.
  5. Save the automation.
  6. Switch back to Visual mode and make whatever changes you may require (such as setting the correct entity_ids for your timer and light).
2 Likes

so im stuck at id
why id 5 and id 0 ?
plus i get this message

Change this:

  - id: 5

to this:

  - id: '5'

Change this:

  - id: 0

to this:

  - id: '0'

Then save the automation let me know if there are any other error messages.

The two id values are used to set the light’s brightness level.

  • When the timer starts, the first Event Trigger is triggered and its id value is used to set the light’s brightness to 5%.
  • When the timer finishes, the second Event Trigger is triggered and its id value is used to set the light’s brightness to 0% (in other words, it turns off the light).
1 Like

Finally it’s working !!!
Thank you all of you, Taras solution work as i want !!!

finally i can sleep now knowing my lights will turn off after x amount of time with 5% dimming :sweat_smile:

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.