Smart light turning on and off

Hello,

Kindly help me this automation. I need to turn on a smart bulb in the morning after 7:00 am, but my problem is we have very frequent power cuts in our area. I am very new to Homeassistant. I am using the following automation. But it didnt worked today, Homeassistant was started today at 6:00 am.

alias: Morning Bulb
description: ""
trigger:
  - platform: homeassistant
    event: start
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: light.morning_bulb
        state: "off"
      - condition: time
        after: "07:00:00"
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.morning_bulb
mode: single

What changes do I have to make in the automation so that the bulb should turn on after 7:00 am even if the power comes back at 7:10 am and the bulb must turn off at 9:30 pm.

Kindly Help.

Best Regards
Neha

Think about what happened.

  • Trigger HA started at 6AM
  • Condition was: MUST be after 7AM
    Result: Automation would not be triggered, because when started it was not after 7AM.
1 Like

Yes that’s right. What trigger can I use then, the main problem are the random power cuts. Kindly help

The problem isn’t the trigger, it’s the condition.

Instead of after: "07:00:00" you want before: "21:30:00" or whatever the last time it should turn the light on is.

Or trigger on HA start up, condition between the times you want it to happen. Could add another trigger at 7 if you want it to come on even if HA is already running.

If I change after to before. Let’s say I change it as below

trigger:
  - platform: homeassistant
    event: start
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: light.morning_bulb
        state: "off"
      - condition: time
        before: "21:30:00"
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.morning_bulb
mode: single

Now if the server is turned on at 6am the light would turn on as both the conditions would be true. But I want the light to turn on only after 7am even of the server started before 7am.

So I guess I have to include another trigger at 7am if the server starts before 7am as suggested by @Arh .

Not sure you need the morning bulb off bit. As the automation is turning the bulb on and it can only do that if the bulb is off. If the bulb is on it won’t matter if you turn it on again.

And yes put the 7am bit in unless you want the bulb to come on whenever HA is started, Which if say it HA started at 00:01 your bulb would come on then, or basically every time HA starts except between 21:30 and 00:00

I agree… removed the condition which check for bulb state i.e. off

Added the 7 am trigger. The automation is working…

So now of the server is started before or after 7 am, the bulb would turn on but if the server the turned on after 21:30 the bulb would not turn on.

Thanks guys… for your guidance and help…

No problem, Once you get your head around what should be a condition and what should be a trigger, its pretty easy. Soon you will be answering these questions for others who pop in for help :grinning_face_with_smiling_eyes:

Thank you for your kind words. :blush: