Compare if sunrise before or after 7:15

For my automation to open the blinds in the morning, I want the blinds to open no earlier than 7:15 if the sun has already risen. Is sunrise after 7:15, the blinds should open at sunrise. I already have the following automation:

alias: Gordijnmanager
description: ""
trigger:
  - platform: time
    at: "07:15:00"
    id: Openen
  - platform: sun
    event: sunrise
    offset: 0
    id: Openen
    enabled: true
  - device_id: eaf23ea82bae8a3cfdb25647eb694253
    domain: zha
    platform: device
    type: remote_button_double_press
    subtype: button_2
    id: Openen
  - platform: time
    at: "22:00:00"
    id: Sluiten
  - device_id: eaf23ea82bae8a3cfdb25647eb694253
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: button_2
    id: Sluiten
  - platform: sun
    event: sunset
    offset: 0
    id: Sluiten
  - platform: state
    entity_id:
      - media_player.chromecast_huiskamer_2
    to: "on"
    id: Sluit huiskamer
  - platform: state
    entity_id:
      - media_player.chromecast_huiskamer_2
    to: "off"
    id: Open huiskamer
  - platform: state
    entity_id:
      - media_player.kpn_diw7022
    to: "on"
    id: Sluit huiskamer
  - platform: state
    entity_id:
      - media_player.kpn_diw7022
    to: "off"
    id: Open huiskamer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Open
          - condition: template
            value_template: ""
        sequence:
          - service: cover.open_cover
            target:
              entity_id: cover.rolgordijnen
            data: {}
          - service: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.rolgordijn_huiskamer_door_manager
      - conditions:
          - condition: trigger
            id:
              - Sluiten
        sequence:
          - service: cover.close_cover
            metadata: {}
            data: {}
            target:
              entity_id: cover.rolgordijnen
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.rolgordijn_huiskamer_door_manager
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Sluit huiskamer
        sequence:
          - service: cover.close_cover
            metadata: {}
            data: {}
            target:
              area_id: huiskamer
      - conditions:
          - condition: trigger
            id:
              - Open huiskamer
        sequence:
          - service: cover.open_cover
            metadata: {}
            data: {}
            target:
              area_id: huiskamer

My idea is to have a condition at the first option and check if sunrise is before or after 7:15 using a template. So, if sunrise <= 7:15 result should be false, otherwise true. I can’t find how to get the current time and compare it to 7:15.

Just add a time condition (where you have []) for after 07:15. It will affect all the other triggers though. If you don’t want that, break your automation up into two ones. One to deal only with the morning routine and another for the rest.

Well, I thought about that, but you already know what happens: I have to split the automation. It’s my goal to keep this all together in one, if possible. And just with typing this and your answer, I have found the answer to my own question. To check in Option 1 if the time is after 7:14:59.

For anyone interested, here the code:

alias: Gordijnmanager
description: ""
trigger:
  - platform: time
    at: "07:15:00"
    id: Openen
  - platform: sun
    event: sunrise
    offset: 0
    id: Openen
    enabled: true
  - device_id: eaf23ea82bae8a3cfdb25647eb694253
    domain: zha
    platform: device
    type: remote_button_double_press
    subtype: button_2
    id: Openen
  - platform: time
    at: "22:00:00"
    id: Sluiten
  - device_id: eaf23ea82bae8a3cfdb25647eb694253
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: button_2
    id: Sluiten
  - platform: sun
    event: sunset
    offset: 0
    id: Sluiten
  - platform: state
    entity_id:
      - media_player.chromecast_huiskamer_2
    to: "on"
    id: Sluit huiskamer
  - platform: state
    entity_id:
      - media_player.chromecast_huiskamer_2
    to: "off"
    id: Open huiskamer
  - platform: state
    entity_id:
      - media_player.kpn_diw7022
    to: "on"
    id: Sluit huiskamer
  - platform: state
    entity_id:
      - media_player.kpn_diw7022
    to: "off"
    id: Open huiskamer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Open
          - condition: time
            after: "07:14:59"
        sequence:
          - service: cover.open_cover
            target:
              entity_id: cover.rolgordijnen
            data: {}
          - service: input_boolean.turn_off
            target:
              entity_id:
                - input_boolean.rolgordijn_huiskamer_door_manager
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Sluiten
        sequence:
          - service: cover.close_cover
            metadata: {}
            data: {}
            target:
              entity_id: cover.rolgordijnen
          - service: input_boolean.turn_on
            target:
              entity_id:
                - input_boolean.rolgordijn_huiskamer_door_manager
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Sluit huiskamer
          - condition: state
            entity_id: input_boolean.rolgordijn_huiskamer_door_manager
            state: "on"
        sequence:
          - service: cover.close_cover
            metadata: {}
            data: {}
            target:
              area_id: huiskamer
      - conditions:
          - condition: trigger
            id:
              - Open huiskamer
          - condition: state
            entity_id: input_boolean.rolgordijn_huiskamer_door_manager
            state: "off"
        sequence:
          - service: cover.open_cover
            metadata: {}
            data: {}
            target:
              area_id: huiskamer

Ah, that pesky “issue”.

Have a look here: Time condition - inclusive or exclusive? - #25 by parautenbach.

Personally, to avoid any uncertainty, I only use template conditions in cases like yours (I forgot about the above).

Got it. I didn’t give the full set of triggers my full thought, which is why I stated it open-ended. Sometimes the complexity of a single automation isn’t worth it. My own preference is for smaller, specific automations, but I certainly have large, complex ones too.

1 Like