Help with my first automation... turning on and off at specific times

Curious how I can make this simpe procedure a little more robust.

I have a plug I want on at 0100 and off at 2300. As is, it works.

But lets say its 0800 when I create, save, and enable this config. It wont turn on the outlet. Same if I make other changes or reboot hass for some reason it wont turn the outlet on.

Is there a way to set it so instead of exact β€œon” times its something like 0100 AND AFTER?

- alias: Outlet ON
  trigger:
    platform: time
    at: 01:00:00
  action:
    service: switch.turn_on
    entity_id: switch.tasmota_4
  id: 2d41d5145b3e45f382027496c8e9101b

- alias: Outlet OFF
  trigger:
    platform: time
    at: '23:00:00'
  action:
    service: switch.turn_off
    entity_id: switch.tasmota_4
  id: 0789a6ba6c5b426db9de4cad77bdf95a

Yes it will. Next time 1am comes around.

It should already be on in that case. The state is persistent through restarts.

If it is really that critical, this automation will check every minute and turn the switch on if it is beween 1am and 11pm.

- id: outlet_on
  alias: Outlet On
  initial_state: true
  trigger:
    platform: time_pattern
    minutes: '/1'
  condition:
  - condition: time
    after: '01:00:00'
    before: '23:00:00'
  - condition: state
    entity_id: switch.tasmota_4
    state: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.tasmota_4

You still need your off automation.

You can also perform actions when home assistant starts using this trigger:

  trigger:
    platform: homeassistant
    event: start
1 Like

Like this:

- alias: Outlet ON
  trigger:
  - platform: time
    at: 01:00:00
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    after: 01:00:00
    before: 23:00:00
  action:
    service: switch.turn_on
    entity_id: switch.tasmota_4
  id: 2d41d5145b3e45f382027496c8e9101b
- alias: Outlet OFF
  trigger:
  - platform: time
    at: '23:00:00'
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    before: 01:00:00
    after: 23:00:00
  action:
    service: switch.turn_off
    entity_id: switch.tasmota_4
  id: 0789a6ba6c5b426db9de4cad77bdf95a

Heres what I landed on.

- alias: Outlet ON
  trigger:
  - platform: time
    at: '12:00:00'
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    after: '12:00:00'
    before: '13:00:00'
  action:
    service: switch.turn_on
    entity_id: switch.tasmota_4
    
    
    
- alias: Outlet OFF
  trigger:
  - platform: time
    at: '13:00:00'
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    before: '12:00:00'
    after: '13:00:00'
  action:
    service: switch.turn_off
    entity_id: switch.tasmota_4