My automation stops after 1 minute

I’m not the best when it comes to home assistant or coding in general. I have tried to set up an automation to fade in a light when I pick up my phone from the charger.

The trigger works and it will start to fade in. However after 60 seconds pass, the automation stops at whatever brightness it reached and the bulb doesn’t reach full brightness or trigger other lights in the room to come on.

How do you keep the automation going for longer than a minute?

You shouldn’t. Automations that run continuously are vulnerable to interruption. Same goes for long pauses. Could you post your code?

If you’re turning on a dimmable light the action light.turn_on allows you to set a transition time. It may be that the light doesn’t support long transitions - you can test it by entering the command from the automation in Developer Tools | Actions.

alias: Lights on when [Me] Wakes up
description: ""
triggers:
  - type: not_plugged_in
    device_id: [My phone]
    entity_id: [I assume this is the plugged in sensor this seems to work]
    domain: binary_sensor
    trigger: device
conditions:
  - condition: zone
    entity_id: person.[Me]
    zone: zone.home
  - condition: time
    after: "05:00:00"
    before: "11:00:00"
    weekday:
      - sun
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
actions:
  - repeat:
      sequence:
        - action: light.turn_on
          metadata: {}
          data:
            brightness_step_pct: 2
          target:
            device_id: [bedroom light = [Status/Tuya wifi dimming and K temperature bulb]
      until:
        - condition: state
          entity_id: light.main_bedroom_light
          attribute: brightness
          state: 255
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      device_id: [xxxxxxx = Bedside light on a status/tuya plug switch]
mode: single

I used the UI to create the automation since my coding skills are still being worked on.
I’ve removed the IDs here and replaced with a description of the device.

I have checked the Traces and have found an error…

“Executed: 10 November 2024 at 13:31:08
Error: Until condition [{‘condition’: ‘state’, ‘entity_id’: [‘light.main_bedroom_light’], ‘attribute’: ‘brightness’, ‘state’: 127, ‘match’: ‘all’}] terminated because it looped 10000 times.”

So this seems like its running in a loop then stopping but why would it need to run this many times? Would this be a connection issue? Like only a fraction of the cycle commands are making it to the bulb.

Wouldn’t it be easier to use the transition of the light.turn_on action ?

action: light.turn_on
metadata: {}
data:
  transition: 60
  brightness_pct: 100
target:
  entity_id: light.main_bedroom_light

Which means, it will take 60s to go from the current brightness (0% = off) to full brightness (100%) :wink:

1 Like

Bonus, doesn’t use device id’s.

1 Like

Is that a good thing or a bad thing? I think I saw somewhere you shouldn’t.

I don’t think my bulb has that transition service available. Not in the UI or using your code. Using your code, the light just turns immediately to 100%, completing the automation. Hence why I was using the repeat action. I think it might just be the limitations of the hardware and chalk it up to that.
Thank you for your help

Avoid device id’s (use entity states and service calls that refer to entities instead) because when you replace a device the device I’d is destroyed meaning you have to edit all automations referencing iy. Use entities

Also search for Ashley’s light fader script. It’s very robust and feature rich.

1 Like