Automation won't run, can you help

Hi there,
I can’t make this automation run at all.
It is a pretty simple setup, a Zigbee Thirdreality motion sensor night light plugged into an outlet (it goes from clear to detected), a dimmer light switch (Zigbee, I can turn it on and off from HA) that works perfectly as a standalone switch and it has worked fine in other versions of this automation. I am trying to combine two automations into one with a couple more options.
If anyone of you can look at this and knows why it can’t run that way, please let me know.
Thanks

alias: hallway Sunset to Sunrise 10pm plus off option
description: ""
triggers:
  - type: motion
    device_id: 8448b4ef25e7f03036229f0825883813
    entity_id: 517118ec9678b3311fdd8059b665ba22
    domain: binary_sensor
    trigger: device
conditions:
actions:
  - choose:
      - conditions:
          - condition: sun
            after: sunset
            after_offset: "-00.30"
          - condition: time
            before: "22:00:00"
        sequence:
          - type: turn_on
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
      - conditions:
          - condition: time
            after: "22:00:00"
          - condition: sun
            before: sunrise
            before_offset: "00:30"
        sequence:
          - type: turn_on
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
            brightness_pct: 15
      - conditions:
          - type: is_no_motion
            condition: device
            device_id: 8448b4ef25e7f03036229f0825883813
            entity_id: 517118ec9678b3311fdd8059b665ba22
            domain: binary_sensor
            for:
              hours: 0
              minutes: 0
              seconds: 30
        sequence:
          - type: turn_off
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
mode: single

What does the trace say?

Try using state as the trigger. Read this

1 Like

Thanks. I’ll check that out.

I am not sure this will reveal the problem.

It tells that it at least triggered and the time it triggered.
Also that none of the choices were valid condition wise so it stopped.

From there we need to look at the conditions and why they were false.

          - condition: sun
            after: sunset
            after_offset: "-00.30"
          - condition: time
            before: "22:00:00"

This one is due to it not being after sunset.

          - condition: time
            after: "22:00:00"
          - condition: sun
            before: sunrise
            before_offset: "00:30"

Same here, sunrise will already have happend at that time.
I always get confused when working with before, after with sun so someone else can maybe see it they overlap in a weird way.

But you will need to post a trace when it should work. Not a trace from when it should not work.

1 Like

First Issue

That should be a : not a .

Second Issue

When you only define one of before or after in a Sun condition, it does not cross midnight. So you need an Or condition because it will never be both after 22:00 and before sunrise on the same day. Also, technically, the offset should be negative to match the other one…

    - conditions:
        - or:
            - condition: time
              after: "22:00:00"
            - condition: sun
              before: sunrise
              before_offset: "-00:30"

Third Issue

Your third option in the Choose will never execute. The trigger fires on motion, so the sensor will never meet the criteria of is_no_motion for 30 seconds. This should be a second trigger, not a condition.

alias: hallway Sunset to Sunrise 10pm plus off option
description: ""
triggers:
  - id: "on"
    type: motion
    device_id: 8448b4ef25e7f03036229f0825883813
    entity_id: 517118ec9678b3311fdd8059b665ba22
    domain: binary_sensor
    trigger: device
  - id: "off"
    type: is_no_motion
    trigger: device
    device_id: 8448b4ef25e7f03036229f0825883813
    entity_id: 517118ec9678b3311fdd8059b665ba22
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 30
conditions:
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: "on"
          - condition: sun
            after: sunset
            after_offset: "-00:30"
          - condition: time
            before: "22:00:00"
        sequence:
          - type: turn_on
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
      - conditions:
          - condition: trigger
            id: "on"
          - or:
              - condition: time
                after: "22:00:00"
              - condition: sun
                before: sunrise
                before_offset: "-00:30"
        sequence:
          - type: turn_on
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
            brightness_pct: 15
      - conditions:
          - condition: trigger
            id: "off"
        sequence:
          - type: turn_off
            device_id: f56469a500a59fb57d87d4221c2fc920
            entity_id: 2547b45844d77e33e74057e57fcc3999
            domain: light
mode: single
4 Likes

That is very well explained. Thank you so much.