Troubleshooting Automation with Input_Datetime

I’ve been working on setting up an automation for my outdoor lights, and I’m running into an issue with using input_datetime as a condition and trigger. Let me share my setup and what’s happening.

I have two input_datetime entities, input_datetime.african_sunrise and input_datetime.african_sunset, which are updated daily based on the sunrise and sunset times in Mozambique. These are set by a separate automation that runs at 1:00 AM. The main automation is supposed to turn on the lights at sunrise and turn them off at sunset. However, while the lights turn on correctly at sunrise, they aren’t turning off at sunset. Instead, I had to add a failsafe that triggers every 15 minutes to ensure the lights don’t stay on past sunset, which defeats the purpose of having a dynamic end time.

Here’s the automation setup I’m using:

yaml

  • id: ‘1601060469999’
    alias: M Light Cycle
    trigger:
    • platform: time_pattern
      minutes: /15
    • platform: time
      at: input_datetime.african_sunrise
    • platform: time
      at: input_datetime.african_sunset
      condition:
      action:
    • choose:
      • conditions:
        • condition: time
          after: input_datetime.african_sunrise
          before: input_datetime.african_sunset
          sequence:
        • service: switch.turn_on
          data:
          entity_id: - switch.m1_outlet
        • delay: 5
        • service: switch.turn_on
          data:
          entity_id: - switch.m4_outlet
          default:
        • service: switch.turn_off
          data:
          entity_id: - switch.m1_outlet
        • delay: 5
        • service: switch.turn_off
          data:
          entity_id: - switch.m4_outlet
          mode: single

From the logs, I can see that the automation is triggered at sunset, but it’s not passing the condition to turn off the lights. The failsafe works, but it’s not ideal. I’m wondering if there’s something I’m missing in how the choose action interacts with the input_datetime conditions.

Has anyone else encountered this issue or have suggestions on how to fix it? I’d really appreciate any insights or alternative approaches to ensure the lights turn off precisely at sunset without needing the failsafe.