Help - LIFX script and automation stopped working?

Hello again @123, I’m finally working on moving to the newest Hassio version.

I have a question about Condition OR statement with dates. I’m getting an error when using this condition statement below. How do you write Condition OR the proper way?

- alias: Birthday Lights
  trigger:
  - platform: sun
    event: sunset
    offset: "01:00:00"
  condition:
  - condition: or
    conditions:
    - condition: "{{ now().month == 9 and now().day == 13 }}"
    - condition: "{{ now().month == 12 and now().day == 16 }}"
  action:
  - service: notify.ios_phones
    data:
      title: Public Service Announcement
      message: Someone's Birthday Today.
  - repeat:
      while: '{{ now().hour != 3 }}'
      sequence:
      - service: script.birthday_lights_script
  - service: light.turn_off
    entity_id: group.living_room_lights
  mode: single

What I’d like to do is to trigger the birthday script on either those dates, 1 hour after sunset. But it’s giving me an error. Also is the repeat while statement correct? I want the lights to turn off at 3AM.

Also another question, what is the easiest way to write “month, day, year” in condition statement?

Like for example, I’d like to setup Condition OR statements for the dates:

  • 10/20/2021
  • 11/04/2022
  • 01/19/2023

Thanks again!

I’m not 100% sure how you want that automation to work but here’s my understanding of it:

- alias: Birthday Lights
  trigger:
  - platform: sun
    event: sunset
    offset: '01:00:00'
  condition:
  - condition: or
    conditions:
    - '{{ now().month == 9 and now().day == 13 }}'
    - '{{ now().month == 12 and now().day == 16 }}'
    - '{{ now().month == 10 and now().day == 20 and now().year == 2021 }}'
    - '{{ now().month == 11 and now().day == 4 and now().year == 2022 }}'
    - '{{ now().month == 1 and now().day == 19 and now().year == 2023 }}'
  action:
  - service: notify.ios_phones
    data:
      title: Public Service Announcement
      message: Someone's Birthday Today.
  - service: script.birthday_lights_script
  - wait_template: '{{ now().hour == 3 }}'
  - service: light.turn_off
    entity_id: group.living_room_lights
  mode: single

EDIT

Changed condition to logical OR.

1 Like

Thanks! That’s what I was actually wanting to create. I was doing the condition like: and it won’t work. Now I’m almost near the end of finishing on moving to the newest version. Thanks again!

condition:
conditions:
  - condition: '{{ }}'
  - condition: '{{ }}'
  - condition: '{{ }}' 

I even thought the year, month, day condition I was writing was wrong, so I asked – turns out what I wrote was the same as yours. It was just the condition – I don’t need to write condition in every line.

Hello again @123,

I’m testing this light automation / script. And I’m not sure why it’s not looping. What I’d like to do is to loop the light changing from cyan to magenta, on repeat, until 4PM. But testing it now, it doesn’t loop. And it stays on in magenta after changing from cyan.

Removing the “wait_template” turns off the light after the sequence. So maybe it’s the wait_template not working? But how can I keep it looping until 4PM?

Automation:

- alias: Birthday
  trigger:
  - platform: time
    at: '13:05:00'
  condition: '{{ now().month == 2 and now().day == 12 }}'
  action:
  - service: script.birthday_lights
  - wait_template: '{{ now().hour == 14 }}'
  - service: light.turn_off
    entity_id: light.orb_light
  mode: single

Script:

birthday_lights:
  alias: Birthday Lights
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.orb_light
      transition: '1'
      color_name: cyan
      brightness_pct: 65
  - delay: '00:00:03'
  - service: light.turn_on
    data:
      entity_id: light.orb_light
      transition: '1'
      color_name: magenta
      brightness_pct: 65
  - delay: '00:00:03'
  mode: single

I tried replacing the wait_template with this from your previous post:

and it seems to be looping. I’m not sure if this is a good choice? Because from your newer post, you replaced it with the wait_template?

The only problem now is I can’t cancel the script. :smiley:

It didn’t loop because there was nothing in the automation or script that would make it loop.

As you have discovered, you must use repeat to perform looping.

A convenient way to control the looping, namely to stop looping, is to add another condition to while that depends on an input_boolean’s state (i.e. it must be on to permit looping).

while: "{{ (now().hour > 13 or now().hour < 4) and is_state('input_boolean.whatever', 'on') }}"

Thanks @123! I got it working and I can turn it off whenever I need to. You’re the best!

Last question, I’m sorry to bother you again.

while: "{{ (now().hour > 13 or now().hour < 4) and is_state('input_boolean.whatever', 'on') }}"

If I want to end the loop at sunset, do I write it as:

"while: "{{ (now().hour >= 9 or sun.sun == sunset) and is_state('input_boolean.birthday_lights', 'on') }}" 
while: "{{ now().hour >= 9 and is_state('sun.sun', 'above_horizon') and is_state('input_boolean.birthday_lights', 'on') }}" 
1 Like