Automation turns lights off, but not on

I’m hoping someone here can save me from the brink of mental collapse. :slight_smile: I have been fighting this thing for ages. All of my other automations, including those using trigger IDs are working fine.

I have the attached automation setup to turn on/off lights based upon sunrise/sunset. It seems to be turning them off just fine, but it refuses to turn them on at sunset. I can see the sunset event occuring on time in the logs, but when I view the logs for the devices this is supposed to turn on, there are no entries at all.

alias: "Lights: Sunrise Sunset"
description: Lights sunrise sunset
trigger:
  - platform: sun
    event: sunrise
    offset: 0
    id: sssunrise
  - platform: sun
    event: sunset
    offset: 0
    id: sssunset
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - sssunset
        sequence:
          - service: light.turn_on
            data:
              rgb_color:
                - 255
                - 255
                - 255
              brightness: 255
              brightness_pct: 100
            target:
              device_id:
                - c4945a1b9fb200a3d44c1cd110c6383c
                - 5961b8baf9ea97c00b6e8f4684008274
                - 1fff96a0f5693e162b5e7a1499627541
          - service: light.turn_on
            data:
              brightness: 255
              brightness_pct: 100
              profile: Fireplace
            target:
              device_id:
                - 3635b615ca458d1d2c5421ab54e7538d
                - e16a63476726bacba0fbdc6008a20a9f
          - type: turn_off
            device_id: 1d25e8a3b6f96645e2103009979b00af
            entity_id: f671c53229d2deea6193df3ed1e4ecd0
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - sssunrise
        sequence:
          - service: light.turn_off
            data: {}
            target:
              device_id:
                - c4945a1b9fb200a3d44c1cd110c6383c
                - 5961b8baf9ea97c00b6e8f4684008274
                - 1fff96a0f5693e162b5e7a1499627541
                - 3635b615ca458d1d2c5421ab54e7538d
                - e16a63476726bacba0fbdc6008a20a9f
          - type: turn_on
            device_id: 1d25e8a3b6f96645e2103009979b00af
            entity_id: f671c53229d2deea6193df3ed1e4ecd0
            domain: switch
mode: single

Try this version.

alias: "Lights: Sunrise Sunset"
description: Lights sunrise sunset
trigger:
  - platform: sun
    event: sunrise
  - platform: sun
    event: sunset
condition: []
action:
  - if: "{{ trigger.event == 'sunset' }}"
    then:
      - service: light.turn_on
        data:
          rgb_color:
            - 255
            - 255
            - 255
          brightness_pct: 100
        target:
          device_id:
            - c4945a1b9fb200a3d44c1cd110c6383c
            - 5961b8baf9ea97c00b6e8f4684008274
            - 1fff96a0f5693e162b5e7a1499627541
      - service: light.turn_on
        data:
          brightness_pct: 100
          profile: Fireplace
        target:
          device_id:
            - 3635b615ca458d1d2c5421ab54e7538d
            - e16a63476726bacba0fbdc6008a20a9f
      - type: turn_off
        device_id: 1d25e8a3b6f96645e2103009979b00af
        entity_id: f671c53229d2deea6193df3ed1e4ecd0
        domain: switch
    else:
      - service: light.turn_off
        data: {}
        target:
          device_id:
            - c4945a1b9fb200a3d44c1cd110c6383c
            - 5961b8baf9ea97c00b6e8f4684008274
            - 1fff96a0f5693e162b5e7a1499627541
            - 3635b615ca458d1d2c5421ab54e7538d
            - e16a63476726bacba0fbdc6008a20a9f
      - type: turn_on
        device_id: 1d25e8a3b6f96645e2103009979b00af
        entity_id: f671c53229d2deea6193df3ed1e4ecd0
        domain: switch
mode: single

References:
Sun Template Variables

When you refer to ‘logs’ are you talking about the the logbook & if so what about the automation traces. Any different clues in the trace?
Also, does the action block for the sunset run successfully if you manually trigger it?

In the log book I see that the sunset even occurs, but nothing in the automation based on the sun setting even triggers. However, I may have just found the issue. In the automation trace I see the following error. I don’t have much experience reading the automation traces.

It looks like it doesn’t like having 2 brightness values.

That’s why the example I posted yesterday specifies just one brightness option (namely brightness_pct).


FWIW, this is one of the few ways that it can accept two brightness options.

- service: light.turn_on
  data:
    brightness_pct: 100
    profile: Fireplace

If your light profile specifies a brightness value, the addition of a brightness_pct or brightness option to the service call serves to override the one in the profile.

Thank you. I’ll test this over night and if it works, mark it as the solution.

1 Like

If you want, you can test the service call separately. Copy-paste the following into Developer Tools > Services.

service: light.turn_on
data:
  rgb_color:
    - 255
    - 255
    - 255
  brightness_pct: 100
target:
  device_id:
    - c4945a1b9fb200a3d44c1cd110c6383c
    - 5961b8baf9ea97c00b6e8f4684008274
    - 1fff96a0f5693e162b5e7a1499627541

Thank you. I was able to resolve this. It was the dual brightness value. For testing, I wound up duplicating the automation, changing the on/off time and simply testing it several times. Thanks for everyone’s help!