Sleep Mode enhanced

hello,
I am using the following scrip as “SLEEP MODE” before we go to sleep.

'1580927569478':
  alias: SLEEP MODE
  sequence:
  - service: input_boolean.turn_on
    entity_id: input_boolean.sleep_mode
  - service: light.turn_off
    data:
      entity_id:
      - light.attic_left_spots
      - light.attic_right_spots
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_1_115c12
      - switch.shelly_shsw_1_115e00
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_25_10521c458680_1
      - switch.shelly_shsw_25_10521c458680_2
      - switch.shelly_shsw_1_500291f0a185
      - switch.shelly_shsw_1_113e36
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_1_500291f04788
      - switch.shelly_shsw_25_10521c458c3f_1
      - switch.shelly_shsw_25_10521c458c3f_2
      - switch.shelly_shsw_25_10521c4447cd_1
      - switch.shelly_shsw_25_10521c4447cd_2
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_25_40f520241f05_2
      - switch.shelly_shsw_25_40f520241f05_1
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - group.office_lights
  - delay: 00:00:01
  - service: switch.turn_off
    entity_id: switch.attictv_tplink
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ states.sensor.time.state > ''21:00'' and states.sensor.time.state
          < ''24:00'' or states.sensor.time.state > ''00:00'' and states.sensor.time.state
          < ''03:00'' }}'
      sequence:
      - service: notify.alexa_media_attic
        data:
          data:
            type: tts
          message: 'Good night. ''{{ ["You are a child of God.", "Sleep well!", "God
            is good ALL the time!"] | random }}'' '
    default: []
  - delay: 00:00:04
  - condition: state
    entity_id: climate.attic_thermostat
    state: heat
  - service: media_player.volume_set
    data:
      volume_level: 1
      entity_id: media_player.attic
    entity_id: media_player.attic
  - service: notify.alexa_media_attic
    data:
      data:
        type: tts
      message: Attention! The attic thermostat is switched on. It will not switch
        off automatically until 12 o'clock. Please make sure you switch it off manually.
  mode: single

It works great and we are very happy with it.
I want to make a small fix but I don’t know if it is possible.

The above script is switching off all the lights / switches before we go to sleep.
it plays a goodnight message via alexa tts between 21:00 - 03:00 am.
it reminds us that the thermostat was not switched off automatically via alexa tts.

And it switches ON a security light to have time to go to bed.

Sometimes we use this automation during the day (e.g. afternoon when we leave the house) and I want to switch on this light only at the night.

I tried to add a template but when is day (not true) the rest of the script is not been executed.

{{ states.sun.sun.state == 'below_horizon' }}

Any help will be much appreciated.

Your automation already uses a choose to check if the time is after 21:00 when it plays a goodnight notification. Why not turn on the security light in the same choose statement? Just add a service call to turn on the security light after the notification.

hello,
thank you for your prompt reply.

I noticed that myself, but is there a way I can have both conditions ?
If not then I will just add a service call to turn on the light after the notification.

You could add a second choose, with its own condition and sequence, to turn on the security light.

thank you,
I tried a second choose. This is what I did at the first place.

But is not working.
I dig it a bit deeper and found that based on the docs if the first choose is true, then the rest are not been executed.

So this is not what I want exactly.

A choose statement can have one or more conditions and/or a default. The first matching conditions is executed (or default) and no others within that choose statement. However, an automation can have more than one choose statement and each one is evaluated separately.

Am afraid that I do something wrong or you are making a mistake.
I confirm that the 2nd choose never runs if the first choose is true and eventually is been executed. Here is what I’ve tried. The 2nd choose never ran.

'1580927569478':
  alias: SLEEP MODE
  sequence:
  - service: input_boolean.turn_on
    entity_id: input_boolean.sleep_mode
  - service: light.turn_off
    data:
      entity_id:
      - light.attic_left_spots
      - light.attic_right_spots
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_1_115c12
      - switch.shelly_shsw_1_115e00
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_25_10521c458680_1
      - switch.shelly_shsw_25_10521c458680_2
      - switch.shelly_shsw_1_500291f0a185
      - switch.shelly_shsw_1_113e36
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_1_500291f04788
      - switch.shelly_shsw_25_10521c458c3f_1
      - switch.shelly_shsw_25_10521c458c3f_2
      - switch.shelly_shsw_25_10521c4447cd_1
      - switch.shelly_shsw_25_10521c4447cd_2
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - switch.shelly_shsw_25_40f520241f05_2
      - switch.shelly_shsw_25_40f520241f05_1
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id:
      - group.office_lights
  - delay: 00:00:01
  - service: switch.turn_off
    entity_id: switch.attictv_tplink
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ states.sun.sun.state == ''below_horizon'' }}'
      sequence:
      - service: switch.turn_on
        entity_id: switch.shelly_shsw_1_500291f09a08
    default: []
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ states.sensor.time.state > ''21:00'' and states.sensor.time.state
          < ''24:00'' or states.sensor.time.state > ''00:00'' and states.sensor.time.state
          < ''03:00'' }}'
      sequence:
      - service: notify.alexa_media_attic
        entity_id: switch.shelly_shsw_1_500291f09a08
        data:
          data:
            type: tts
          message: 'Good night. ''{{ ["You are a child of God.", "Sleep well!", "God
            is good ALL the time!"] | random }}'' '
    default: []
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - condition: state
    entity_id: climate.attic_thermostat
    state: heat
  - service: media_player.volume_set
    data:
      volume_level: 1
      entity_id: media_player.attic
    entity_id: media_player.attic
  - service: notify.alexa_media_attic
    data:
      data:
        type: tts
      message: Attention! The attic thermostat is switched on. It will not switch
        off automatically until 12 o'clock. Please make sure you switch it off manually.
  mode: single

please forgive me and ignore my previous message.
The script was raising an error in log files which I just saw.

This was the reason choose 2 was not been executed.
Problem has been solved.