Blueprint - Toggle device after a period of time

I created this blueprint to toggle a device after a period of time. For example, it can turn a switch off ‘x’ minutes after it was turned on, or turn a switch on ‘x’ minutes after it was turned off. Great for things like heating devices, etc. where you want to automatically turn them off (e.g. electric blankets, etc.).

As input, it asks for the device to monitor and toggle (trigger_device), the trigger state that starts the timer (e.g. on or off), and the duration before toggling the switch (hh:mm:ss).

Here’s the gist

And here’s the code:

blueprint:
  name: Toggle device status after a period of time
  description: "Once a device has been in a defined status for a period of time, toggle it's status"
  domain: automation
  input:
    trigger_device:
      name: Device
      description: Which device to monitor and toggle?
      selector:
        entity:
    trigger_state:
      name: State
      description: What state begins time period?
    trigger_time:
      name: Duration
      description: What period to wait before toggling state?
      selector:
        time:

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input trigger_device
  to: !input trigger_state
  for: !input trigger_time

action:
  service: homeassistant.toggle
  data:
    entity_id: "{{ trigger.entity_id }}"

This is my first blueprint, so I hope it’s useful and improvements welcome!

I’d ideally like to tweak it to be able to monitor and toggle multiple devices using the same automation.

1 Like

This has already been posted here:

Not quite the same as that only allows a device to be on for a period of time. This allows it to be off too.

1 Like

very useful! the “off” state is a very good implementation.
The duration field shows also AM/PM and the HH always defaults to 12, do you know if exists some other kind of input to show HH:MM:SS?

ok found… you should try duration: instead of time:

docs here: duration-selector