Trigger.entity_id

I am trying to write an automation that turns off any light on longer than 1 minute. The automation below trigger after one minute, but the study lights do not toggle. Any suggestions please.

id: '1661835107535'
alias: Turn off lights and fans
description: ''
trigger:
  - platform: state
    entity_id:
      - light.study_lights
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: light.toggle
    data: {}
    target:
      entity_id: trigger.entity_id
mode: single

You are using a string. You need to make it a template

action:
  - service: light.toggle
    data: {}
    target:
      entity_id: "{{ trigger.entity_id }} "

Perhaps you should consider using light.turn_off ?

1 Like

Thank you. But now I am getting an error message.
Executed: August 30, 2022 at 4:41:49 PM

Error: Template rendered invalid entity IDs:

id: '1661835107535'
alias: Turn off lights and fans
description: ''
trigger:
  - platform: state
    entity_id:
      - light.study_lights
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: '{{ trigger.entity_id }}'
mode: single

Huh…

There should be a trigger.entity_id

Automation Trigger Variables - Home Assistant (home-assistant.io)

1 Like

If you tested it by running the automation manually there will be no trigger and thus no trigger.entity_id.

Leave the light on for a minute and see what happens.

Thank you. Works perfectly.

I’m also struggling to get my lights on longer than 1 min but no clue what code to put into the yaml file.

I have never used this code before and until I learn or get used to what to put in there I have no clue and dont want to make mistakes in there to stop things from working.

I can see where my Automation is in the file just no clue what to add to it for the light to stop on 3 mins

I’m also having issues with lights blinking when using the Aqara Presence Sensor FP2 and totally given up with that sensor. I tried to set it up after nightnight to turn on if I was to have to get up during the night due to hypo to get food from Kitchen and have the lights come on but all I got was more confusions with blinking lights with blinking hypo :rofl: :ok_hand:

Please start a separate thread and include all pertinent information, including the automation’s yaml, as outlined in How To Help Us Help You.