Issues with scheduled power cycle for smart plug

I have the following automation to schedule poweron/off a smart plug during the day.

alias: Smart plug Scheduler
description: Turns on/off smart plug during the day
trigger:
  - platform: time
    at: "00:00:00"
    id: 12 AM
  - platform: time
    at: "06:00:00"
    id: 6 AM
  - platform: time
    at: "12:00:00"
    id: 12 PM
  - platform: time
    at: "18:00:00"
    id: 6 PM
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 12 AM
        sequence:
          - type: turn_off
            device_id: 397321b5b075866bc7c365f9d04dd1e4
            entity_id: switch.air_purifier
            domain: switch
      - conditions:
          - condition: trigger
            id: 6 AM
        sequence:
          - type: turn_on
            device_id: 397321b5b075866bc7c365f9d04dd1e4
            entity_id: switch.air_purifier
            domain: switch
      - conditions:
          - condition: trigger
            id: 12 PM
        sequence:
          - type: turn_off
            device_id: 397321b5b075866bc7c365f9d04dd1e4
            entity_id: switch.air_purifier
            domain: switch
      - conditions: []
        sequence: []
      - conditions:
          - condition: trigger
            id: 6 PM
        sequence:
          - type: turn_on
            device_id: 397321b5b075866bc7c365f9d04dd1e4
            entity_id: switch.air_purifier
            domain: switch
mode: single

The conditions for 6 am and 12 pm work except 6 pm. 12 am doesn’t trigger because 6 pm never powered on. Is there something I am missing here to ensure that 6 pm powers the smart plug back on?

Thank you!

I would probably change this up by doing the following:

  • Create a schedule helper and put in all the times you want the smart plug turned on
  • Set the trigger condition trigger on schedule change
  • Set the action to set the smart switch to the value of the schedule

This will get you two things:

  1. simplifies your logic a lot and makes it easier for you to modify the schedule for different days
  2. ensure that even on a restart of HA your switch will get set correctly