Switch timer every hour at minute 51 for 20 minutes?

Hi,

How can I add a timer here so that the switch automatically turns of after 20 minutes before it switches on again on minute 51.

alias: "Garage Lüfter Timer "
description: ""
trigger:
  - platform: time_pattern
    minutes: "51"
condition: []
action:
  - type: turn_on
    device_id: 9ec6c0db4e4e7efab120b8f9a497f7ba
    entity_id: b1dcef5154360ea5605caa08dade74d0
    domain: switch

Please format your code

and maybe good to know too:

alias: "Garage Lüfter Timer "
description: ""
trigger:
  - id: 'on'
    platform: time_pattern
    minutes: "51"
  - id: 'off'
    platform: time_pattern
    minutes: "11"
condition: []
action:
  - service: "switch.turn_{{ trigger.id }}"
    target: 
      entity_id: switch.your_switch

EDIT

Correction. Replaced platform with service.

1 Like

Seems good to me, just add a second automation

  trigger:
  - entity_id: b1dcef5154360ea5605caa08dade74d0
    for: 00:20
    platform: state
    to: 'on'
  action:
  - data:
      entity_id: b1dcef5154360ea5605caa08dade74d0
    service: switch.turn_off

Better use real entity_id instead of b1dcef5154360ea5605caa08dade74d0

Thanks. Where do I get the trigger.id from?

The value of trigger.id will be the value of the id parameter specified in each one of the two Time Pattern Triggers.

For more information, refer to Available Trigger Data.

You define it yourself in the above section of the code. If you’re using the visual editor, just click on the 3 dots next to the trigger (When) section > Edit ID. Make sure you only use ‘on’ or ‘off’, otherwise the template in the action part won’t work and you’ll have to set up separate actions manually

I suggest you simply copy the example I posted directly into a new automation (or overwrite your existing automation) then replace switch.your_switch with the entity_id of your switch.

For more information, refer to the “How to import an automation from the forum” section of the following post:

1 Like

This is exactly what I have done and what the error causes in the line with the trigger.id

You’re right, I made a mistake. I have corrected the example posted above.

Replace this:

  - platform: "switch.turn_{{ trigger.id }}"

with this:

  - service: "switch.turn_{{ trigger.id }}"

That worked well. Thanks a lot for your kind help. Now I don’t have to use two automations anymore.

1 Like