Sunrise and Sunset Automations not triggering recently

I have 2 simple automations to turn ON and OFF lights at Sunrise and Sunset
they were working perfectly but from past few days they are not being triggered timely
tried numeric_state conditions with elevation but no gain, they are triggered very late or not being triggered at all
tried the suggested elevation values and various other but still no go
I am also attaching trace files of both automations

here is my Sunrise automation:

alias: turn Garage Lights OFF when Sunrise
description: ''
trigger:
  - platform: sun
    event: sunrise
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id:
        - switch.left
        - switch.right
  - repeat:
      until:
        - condition: device
          type: is_off
          device_id: 38f7b17b094084b1ce8f53d07f472247
          entity_id: switch.left
          domain: switch
      sequence:
        - repeat:
            until:
              - condition: device
                type: is_off
                device_id: ae85597e694265fda7d634b10d2413fc
                entity_id: switch.right
                domain: switch
            sequence: []
mode: single

here’s my Sunset automation:

alias: turn Garage Lights ON when Sunset
description: ''
trigger:
  - platform: sun
    event: sunset
condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '1'
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.left
        - switch.right
  - repeat:
      until:
        - condition: device
          type: is_on
          device_id: 38f7b17b094084b1ce8f53d07f472247
          entity_id: switch.left
          domain: switch
        - condition: device
          type: is_on
          device_id: ae85597e694265fda7d634b10d2413fc
          entity_id: switch.right
          domain: switch
      sequence: []
mode: single

here is the trace file of Sunrise automation:

{
  "trace": {
    "last_step": "action/1/repeat/until/0/entity_id/0",
    "run_id": "0",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2021-09-29T01:26:56.600289+00:00",
      "finish": "2021-09-29T01:26:56.867040+00:00"
    },
    "domain": "automation",
    "item_id": "1630929615984",
    "trigger": "sunrise",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2021-09-29T01:26:56.600548+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.turn_garage_lights_off_when_sunrise",
              "state": "on",
              "attributes": {
                "last_triggered": "2021-09-28T01:09:49.153543+00:00",
                "mode": "single",
                "current": 0,
                "id": "1630929615984",
                "friendly_name": "turn Garage Lights OFF when Sunrise"
              },
              "last_changed": "2021-09-28T21:19:04.756797+00:00",
              "last_updated": "2021-09-28T21:19:04.756797+00:00",
              "context": {
                "id": "b61b87f963c0436260183d441f9859d1",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "sun",
              "event": "sunrise",
              "offset": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 0
              },
              "description": "sunrise"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2021-09-29T01:26:56.602075+00:00",
          "changed_variables": {
            "context": {
              "id": "1d6bf9e051d9837bea24b05d0c0403fe",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "switch.left",
                  "switch.right"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2021-09-29T01:26:56.615669+00:00"
        }
      ],
      "action/1/repeat/sequence/0": [
        {
          "path": "action/1/repeat/sequence/0",
          "timestamp": "2021-09-29T01:26:56.807488+00:00",
          "changed_variables": {
            "repeat": {
              "first": false,
              "index": 15
            }
          }
        },
        {
    "config": {
      "id": "1630929615984",
      "alias": "turn Garage Lights OFF when Sunrise",
      "description": "",
      "trigger": [
        {
          "platform": "sun",
          "event": "sunrise"
        }
      ],
      "condition": [],
      "action": [
        {
          "service": "switch.turn_off",
          "target": {
            "entity_id": [
              "switch.left",
              "switch.right"
            ]
          }
        },
        {
          "repeat": {
            "until": [
              {
                "condition": "device",
                "type": "is_off",
                "device_id": "38f7b17b094084b1ce8f53d07f472247",
                "entity_id": "switch.left",
                "domain": "switch"
              }
            ],
            "sequence": [
              {
                "repeat": {
                  "until": [
                    {
                      "condition": "device",
                      "type": "is_off",
                      "device_id": "ae85597e694265fda7d634b10d2413fc",
                      "entity_id": "switch.right",
                      "domain": "switch"
                    }
                  ],
                  "sequence": []
                }
              }
            ]
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "1d6bf9e051d9837bea24b05d0c0403fe",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "turn Garage Lights OFF when Sunrise",
      "message": "has been triggered by sunrise",
      "source": "sunrise",
      "entity_id": "automation.turn_garage_lights_off_when_sunrise",
      "context_id": "1d6bf9e051d9837bea24b05d0c0403fe",
      "when": "2021-09-29T01:26:56.600965+00:00",
      "domain": "automation"
    },
    {
      "when": "2021-09-29T01:26:56.768886+00:00",
      "name": "right",
      "state": "off",
      "entity_id": "switch.right",
      "context_entity_id": "automation.turn_garage_lights_off_when_sunrise",
      "context_entity_id_name": "turn Garage Lights OFF when Sunrise",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "turn Garage Lights OFF when Sunrise",
      "message": "turned off"
    },
    {
      "when": "2021-09-29T01:26:56.864445+00:00",
      "name": "left",
      "state": "off",
      "entity_id": "switch.left",
      "context_entity_id": "automation.turn_garage_lights_off_when_sunrise",
      "context_entity_id_name": "turn Garage Lights OFF when Sunrise",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "turn Garage Lights OFF when Sunrise",
      "message": "turned off"
    }
  ]
}

here is the trace file of Sunset automation:

{
  "trace": {
    "last_step": "condition/0/entity_id/0",
    "run_id": "0",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2021-09-27T12:48:01.254008+00:00",
      "finish": "2021-09-27T12:48:01.255039+00:00"
    },
    "domain": "automation",
    "item_id": "1632650755935",
    "trigger": "sunset with offset",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2021-09-27T12:48:01.254257+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.turn_garage_lights_on_when_sunrise_new",
              "state": "on",
              "attributes": {
                "last_triggered": "2021-09-26T13:13:20.280792+00:00",
                "mode": "single",
                "current": 0,
                "id": "1632650755935",
                "friendly_name": "turn Garage Lights ON when Sunset"
              },
              "last_changed": "2021-09-27T07:14:37.110321+00:00",
              "last_updated": "2021-09-27T07:14:37.110321+00:00",
              "context": {
                "id": "6aafa2926c570faf79f3d8fda0fdd76e",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "sun",
              "event": "sunset",
              "offset": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": -300
              },
              "description": "sunset with offset"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2021-09-27T12:48:01.254575+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2021-09-27T12:48:01.254748+00:00",
          "result": {
            "result": false,
            "state": 0.97,
            "wanted_state_below": -3
          }
        }
      ]
    },
    "config": {
      "id": "1632650755935",
      "alias": "turn Garage Lights ON when Sunset",
      "description": "",
      "trigger": [
        {
          "platform": "sun",
          "event": "sunset",
          "offset": "-00:05:00"
        }
      ],
      "condition": [
        {
          "condition": "numeric_state",
          "entity_id": "sun.sun",
          "attribute": "elevation",
          "below": "-3.00"
        }
      ],
      "action": [
        {
          "service": "switch.turn_on",
          "target": {
            "entity_id": [
              "switch.left",
              "switch.right"
            ]
          }
        },
        {
          "repeat": {
            "until": [
              {
                "condition": "device",
                "type": "is_on",
                "device_id": "38f7b17b094084b1ce8f53d07f472247",
                "entity_id": "switch.left",
                "domain": "switch"
              },
              {
                "condition": "device",
                "type": "is_on",
                "device_id": "ae85597e694265fda7d634b10d2413fc",
                "entity_id": "switch.right",
                "domain": "switch"
              }
            ],
            "sequence": []
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "5f13008bbc3383b9adfa1917d16e6557",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": []
}

Are the following set correctly?

  • Time
  • Timezone
  • Location (including height)

What’s the point of the repeat without actions?
As the mode of the automations are single, they might be still running at sunset/sunrise, so won’t be re-triggered…

2 Likes

yes
they are configured correctly