Single Automation to turn on/off a switch within a time frame

Hi guys, just needing some coding help here, I’d like to keep one of my lights on between the hours of 10pm and 5am and up until now I’ve had 2 automations handling this but I would really like just one, here’s what I’ve got so far:

automation:

  • alias: Turn on Backdoor at 22:00
    hide_entity: False
    trigger:
    • platform: time
      seconds: ‘/3’
      condition:
      condition: time
      after: ‘17:08:00’
      before: ‘17:08:30’
      action:
    • service: light.turn_on
      entity_id: light.backdoor

I feel like it has something to do with the light.turn_on part… I thought maybe something like light.payload…
I’m not a coder so I’m not sure, as no errors are thrown and the light does turn on.

There’s no simple method to accomplish this. It’s currently best practice to use separate automations for ‘on’ and ‘off.’

1 Like

You could totally do this in one thing. You’d have to add two triggers, one at your start time and one at your end time. You can leave your condition the same. In your action you’d have to template it so that you can figure if you should turn on or off based on what time it is.

1 Like

But is this more efficient than two separate automations?

Can you please show me with the code I have provided, or at least give me an idea. I’m not a coder but I’ll figure it out with logic with what you provide haha :slight_smile:

@Bahnburner perhaps but for the front end I’d prefer 1 automation to be active to do multiple things than 2 :slight_smile:

[quote=“HellfireZA, post:5, topic:18888, full:true”]@Bahnburner perhaps but for the front end I’d prefer 1 automation to be active to do multiple things than 2 :slight_smile:
[/quote]

If your concerned with how they would appear on the front end, you could always combine the automations in a group, hide the group and the automations from the frontend, and then use a template switch to turn the group on and off.

@Bahnburner Maybe? It’s definitely harder to follow.

True! I’ll try that approach, does seem more logical actually and I do have my various groups setup already… thanks man :slight_smile:

1 Like