Custom Component: Delayed Action

Delayed Action Home Assistant Integration

hacs
GitHub Sponsors

The delayed_action integration allows you to schedule actions for Home Assistant entities with a delay or at a specific time. This integration supports various entities and actions, providing flexibility in controlling your devices.

Features

  • Schedule actions with a delay (in seconds).
  • Schedule actions at a specific date and time (ISO 8601 format).
  • Pass additional data to the actions.

Installation:

HACS (Home Assistant Community Store)

  1. Go to HACS page on your Home Assistant instance
  2. Add this repository (GitHub - bhuebschen/delayed_action) via HACS Custom repositories How to add Custom Repositories
  3. Select Integration
  4. Press add icon and search for Delayed Action
  5. Select Delayed Action repo and install
  6. Restart Home Assistant
  7. Add delayed_action to your page

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

Manual

  1. Ensure your Home Assistant configuration directory has the following structure:
/config/custom_components/delayed_action/
├── init.py
├── manifest.json
├── config_flow.py
├── const.py
└── services.yaml
  ├── translations/de.json
  └── translations/en.json
  1. Copy the provided files into the custom_components/delayed_action/ directory.
  2. Restart Home Assistant to load the new custom component.

Configuration

  1. Go to Configuration → Devices & Services.
  2. Click on the “+” button and add the “Delayed Action” integration.

Usage

You can use the delayed_action.execute service to schedule actions with a delay or at a specific time.

Service Data Attributes

  • entity_id (required): The entity ID of the device to control.
  • action (required): The action to perform (e.g., turn_on, turn_off, set_brightness, set_temperature).
  • delay (optional): The delay in seconds before performing the action.
  • datetime (optional): The specific date and time to perform the action (ISO 8601 format).
  • additional_data (optional): Any additional data to be passed to the service call.

Examples

Script: Turn On with Delay

script:
  turn_on_with_delay:
    sequence:
      - service: delayed_action.execute
        data:
          entity_id: switch.any_switch
          delay: 10  # Delay in seconds
          action: turn_on

Script: Set Brightness with Delay

script:
  set_brightness_with_delay:
    sequence:
      - service: delayed_action.execute
        data:
          entity_id: light.any_light
          delay: 15  # Delay in seconds
          action: turn_on
          brightness: 128

Development

To develop and test this integration:

  1. Clone the repository into your Home Assistant custom_components directory.
  2. Make changes to the code as needed.
  3. Restart Home Assistant to apply the changes.

Troubleshooting

If you encounter issues, check the Home Assistant logs for error messages. Common issues include:

  • Ensuring the entity_id is correct and exists.
  • Verifying the action is supported for the specified entity.
  • Confirming the date and time are in the correct format.

For more information on Home Assistant custom components, visit the Home Assistant Developer Documentation.

Contributing

Contributions are welcome! Please submit a pull request with your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

3 Likes

Hi, I currently use timers to delay actions, are there any advantages if I were to switch over to your integration?

What is the advantage of doing this:

script:
  example1:
    sequence:
      - service: delayed_action.execute
        data:
          entity_id: switch.foo
          delay: 60
          action: turn_on

compared to this:

script:
  example2:
    sequence:
      - delay: 60
      - service: switch.turn_on
        target:
          entity_id: switch.foo

The purpose of this integration is to dynamically schedule the start or stop of a device without creating an automation.

For example, if I am at work and know that I will be home in 2 hours, I can switch on the air conditioning in 1.5 hours.

When I go to bed, I can say that the air conditioning will switch off in an hour… tomorrow maybe only after 2 hours.

The next days, i will create a card to be able to set the delay via UI for every device.

1 Like

that you can delay an action without having a script, i.e. directly from a dashboard with any device… and without an predefined delay in the script.

1 Like

I see. That wasn’t clear because the example you posted is a script.

So you mean delayed_action.execute is useful because it can be called as a single action by a card, like a Button card, with no need for a script. Is that correct?

Thats correct :slight_smile:

If there is no predefined delay, how do you pass the desired delay value to the card’s action?

ezgif-3-6a80687a69

my plan is to pass it from the ui like this… but the card is not ready

currently it looks like this… i’ve added the possibility to list and cancel a task… i think i can publish the ui-part on weekend

So… UI is now released: GitHub - bhuebschen/delayed-action-card

I would appreciate feedback :slight_smile:

My ac units use input_select to turn on the desire modes. Is it possible with this integration??

Please try the 0.1.4 pre-release and you also need to install the 1.0.1 pre-release of the card-component

The “delayed-action-card” now also supports

  • Light-Card
  • Mushroom-Select
  • Mushroom-Fan
  • Mushroom-Lock
  • Mushroom-Vacuum