Automation is not fired

I made this automation that should Turn lights and announce on kitchen display when I come home after sunset and before 2 am.
I can trigger the automation manually and it works fine. But it’s not working when I come home.
Is there’s any thing that I miss.

> alias: لما أوصل البيت
> description: ""
> trigger:
>   - alias: لما أوصل البيت
>     platform: zone
>     entity_id: device_tracker.ihsan_iphone_10
>     zone: zone.home
>     event: enter
> condition:
>   - condition: sun
>     after: sunset
>   - condition: time
>     before: "02:00:00"
> action:
>   - alias: اضيء النور
>     type: turn_on
>     device_id: a4b0f2fedc9cd1fa16614d23423cf144
>     entity_id: d0a693dc83a586c67f2fa4ca7e04e78a
>     domain: light
>     brightness_pct: 100
>   - service: tts.google_translate_say
>     metadata: {}
>     data:
>       cache: false
>       entity_id: media_player.kitchen_display
>       message: Welcome home my boss
> mode: single

Please format your code as recommended here: Format it Properly

As @MaxK says, it’s hard to read your code without proper formatting, but I think your conditions are impossible - before 02:00 and after sunset on the same day.

This is a problem that arises when you use sunrise or sunset conditions - you could try below horizon instead:

Running an automation manually only tests the action part - trigger and conditions are ignored.

1 Like

Thank you for reply
I am trying to edit the automation . I can’t find these sign <> . I copied the automation from yaml and pasted here using my iPhone . I will try to find out how to do it :slightly_smiling_face::pray:

Thank you for reply
I deleted the condition before am and make it when Sun below horizon.
I will try it today :slightly_smiling_face::pray:

I tried the automation after adjustment but it still not working


alias: لما أوصل البيت
description: ""
trigger:
  - alias: لما أوصل البيت
    platform: zone
    entity_id: device_tracker.ihsan_iphone_10
    zone: zone.home
    event: enter
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - alias: اضيء النور
    type: turn_on
    device_id: a4b0f2fedc9cd1fa16614d23423cf144
    entity_id: d0a693dc83a586c67f2fa4ca7e04e78a
    domain: light
    brightness_pct: 100
  - service: tts.google_translate_say
    metadata: {}
    data:
      cache: false
      entity_id: media_player.kitchen_display
      message: Welcome home my boss
mode: single

I tried the automation after adjustment.still not working. Any idea :slightly_smiling_face:

alias: لما أوصل البيت
description: ""
trigger:
  - alias: لما أوصل البيت
    platform: zone
    entity_id: device_tracker.ihsan_iphone_10
    zone: zone.home
    event: enter
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - alias: اضيء النور
    type: turn_on
    device_id: a4b0f2fedc9cd1fa16614d23423cf144
    entity_id: d0a693dc83a586c67f2fa4ca7e04e78a
    domain: light
    brightness_pct: 100
  - service: tts.google_translate_say
    metadata: {}
    data:
      cache: false
      entity_id: media_player.kitchen_display
      message: Welcome home my boss
mode: single

Please post the automation trace, so we can see, what’s not running… :slight_smile:

I copied the traces . I don’t know if it’s the right way:


{
  "trace": {
    "last_step": "condition/0/entity_id/0",
    "run_id": "b7bdf7ce530b622d4202305bce8c49cb",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2024-05-15T14:08:19.887794+00:00",
      "finish": "2024-05-15T14:08:19.888287+00:00"
    },
    "domain": "automation",
    "item_id": "1714673139504",
    "trigger": "device_tracker.ihsan_iphone_10 entering Home",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-05-15T14:08:19.887894+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.lm_wsl_lbyt",
              "state": "on",
              "attributes": {
                "id": "1714673139504",
                "last_triggered": "2024-05-13T18:46:52.764159+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "لما أوصل البيت"
              },
              "last_changed": "2024-05-14T04:47:52.256398+00:00",
              "last_reported": "2024-05-14T04:47:52.256398+00:00",
              "last_updated": "2024-05-14T04:47:52.256398+00:00",
              "context": {
                "id": "01HXTPVAE0WD8M53D4C44SXG8G",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": "لما أوصل البيت",
              "platform": "zone",
              "entity_id": "device_tracker.ihsan_iphone_10",
              "from_state": {
                "entity_id": "device_tracker.ihsan_iphone_10",
                "state": "not_home",
                "attributes": {
                  "source_type": "gps",
                  "battery_level": 44,
                  "latitude": 55.728179931640625,
                  "longitude": 9.631737272273508,
                  "gps_accuracy": 8.001208273680877,
                  "altitude": 77.12012061374745,
                  "course": 116.30726623535156,
                  "speed": 6.987085342407227,
                  "vertical_accuracy": 3,
                  "friendly_name": "Ihsan iPhone 10"
                },
                "last_changed": "2024-05-15T14:08:08.829411+00:00",
                "last_reported": "2024-05-15T14:08:08.829411+00:00",
                "last_updated": "2024-05-15T14:08:08.829411+00:00",
                "context": {
                  "id": "01HXY99Y3XBQK50HGBTJFAKGF6",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "device_tracker.ihsan_iphone_10",
                "state": "home",
                "attributes": {
                  "source_type": "gps",
                  "battery_level": 44,
                  "latitude": 55.728271484375,
                  "longitude": 9.633886701547656,
                  "gps_accuracy": 12.001812410521316,
                  "altitude": 71.57491646548979,
                  "course": 125.15872227600991,
                  "speed": 0.45646771788597107,
                  "vertical_accuracy": 3,
                  "friendly_name": "Ihsan iPhone 10"
                },
                "last_changed": "2024-05-15T14:08:19.882237+00:00",
                "last_reported": "2024-05-15T14:08:19.882237+00:00",
                "last_updated": "2024-05-15T14:08:19.882237+00:00",
                "context": {
                  "id": "01HXY9A8XA66ZMB71JZCH5BTX6",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "zone": {
                "entity_id": "zone.home",
                "state": "3",
                "attributes": {
                  "latitude": 55.72843683836487,
                  "longitude": 9.633977651465102,
                  "radius": 100,
                  "passive": false,
                  "persons": [
                    "person.home",
                    "person.ihsan_iphone",
                    "person.my_car"
                  ],
                  "editable": true,
                  "icon": "mdi:home",
                  "friendly_name": "Home"
                },
                "last_changed": "2024-05-15T14:08:19.884513+00:00",
                "last_reported": "2024-05-15T14:08:19.884513+00:00",
                "last_updated": "2024-05-15T14:08:19.884513+00:00",
                "context": {
                  "id": "01HXY9A8XC5H636TYQCAGQ6ERG",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "event": "enter",
              "description": "device_tracker.ihsan_iphone_10 entering Home"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2024-05-15T14:08:19.887959+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2024-05-15T14:08:19.888017+00:00",
          "result": {
            "result": false,
            "state": "above_horizon",
            "wanted_state": "below_horizon"
          }
        }
      ]
    },
    "config": {
      "id": "1714673139504",
      "alias": "لما أوصل البيت",
      "description": "",
      "trigger": [
        {
          "alias": "لما أوصل البيت",
          "platform": "zone",
          "entity_id": "device_tracker.ihsan_iphone_10",
          "zone": "zone.home",
          "event": "enter"
        }
      ],
      "condition": [
        {
          "condition": "state",
          "entity_id": "sun.sun",
          "state": "below_horizon"
        }
      ],
      "action": [
        {
          "alias": "اضيء النور",
          "type": "turn_on",
          "device_id": "a4b0f2fedc9cd1fa16614d23423cf144",
          "entity_id": "d0a693dc83a586c67f2fa4ca7e04e78a",
          "domain": "light",
          "brightness_pct": 100
        },
        {
          "service": "tts.google_translate_say",
          "metadata": {},
          "data": {
            "cache": false,
            "entity_id": "media_player.kitchen_display",
            "message": "Welcome home my boss"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HXY9A8XF40HFKZ1DZPDHMX0K",
      "parent_id": "01HXY9A8XA66ZMB71JZCH5BTX6",
      "user_id": null
    }
  },
  "logbookEntries": []
}

The trace shows (if I read it correctly) that the automation was stopped as the conditions was not met, the sun was still above the horizon. Is your time, time-zone and location setup correcly, if you tried to run this when it was dark?

As you can see on the part that @baunan posted, the condition “below_horizon” wasn’t matched.

The sun and its states are tricky, because “below_horizon” doesn’t necessarily mean, it’s dark outside. Depending on landscape, elevation and other factors, the sun can be below the horizon and it’s not dark or vice versa.

If you want to have a more granular control you could work with the sun elevation, but even that has a range throughout the year. In my case in the winter months a sun elevation under 10° means dark, whereas in the summer month it gets dark with an elevation value around -13°.

You’ll need to find a way, to make this work for you and your circumstances. One way could be, to go with the times for sunrise and sundown. The sun integration gives you exact times for the day, if you use these, it might work better.

Thank for supporting and for help. But unfortunately my automation still not working.
I changed the condition to after sun set but it didn’t work and then removed the condition at all and also didn’t work.

Maybe something is missing :thinking:

post the trace w/ the condition completely removed.

Here is the copy of traces:


{
  "trace": {
    "last_step": "action/1",
    "run_id": "efc2d37ffc5e486643f02398c6c0621b",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-05-17T21:01:51.388982+00:00",
      "finish": "2024-05-17T21:02:02.593299+00:00"
    },
    "domain": "automation",
    "item_id": "1714673139504",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2024-05-17T21:01:51.389100+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.lm_wsl_lbyt",
              "state": "on",
              "attributes": {
                "id": "1714673139504",
                "last_triggered": "2024-05-17T18:53:41.493763+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "لما أوصل البيت"
              },
              "last_changed": "2024-05-17T20:54:28.942814+00:00",
              "last_reported": "2024-05-17T20:54:28.942814+00:00",
              "last_updated": "2024-05-17T20:54:28.942814+00:00",
              "context": {
                "id": "01HY45BCTEBD2TA63ZZ24J6A9X",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-05-17T21:01:51.389640+00:00",
          "changed_variables": {
            "context": {
              "id": "01HY45RWWW3RF5SMM45WWA33TT",
              "parent_id": "01HY45RWWW1AJVFX49R9GYB2HB",
              "user_id": null
            }
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2024-05-17T21:01:51.458623+00:00",
          "result": {
            "params": {
              "domain": "tts",
              "service": "google_translate_say",
              "service_data": {
                "cache": false,
                "entity_id": "media_player.kitchen_display",
                "message": "Welcome home my boss"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1714673139504",
      "alias": "لما أوصل البيت",
      "description": "",
      "trigger": [
        {
          "alias": "لما أوصل البيت",
          "platform": "zone",
          "entity_id": "device_tracker.ihsan_iphone_10",
          "zone": "zone.home",
          "event": "enter"
        }
      ],
      "condition": [],
      "action": [
        {
          "alias": "اضيء النور",
          "type": "turn_on",
          "device_id": "a4b0f2fedc9cd1fa16614d23423cf144",
          "entity_id": "d0a693dc83a586c67f2fa4ca7e04e78a",
          "domain": "light",
          "brightness_pct": 100
        },
        {
          "service": "tts.google_translate_say",
          "metadata": {},
          "data": {
            "cache": false,
            "entity_id": "media_player.kitchen_display",
            "message": "Welcome home my boss"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HY45RWWW3RF5SMM45WWA33TT",
      "parent_id": "01HY45RWWW1AJVFX49R9GYB2HB",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "لما أوصل البيت",
      "message": "triggered",
      "source": null,
      "entity_id": "automation.lm_wsl_lbyt",
      "context_id": "01HY45RWWW3RF5SMM45WWA33TT",
      "when": 1715979711.389193,
      "domain": "automation"
    },
    {
      "when": 1715979714.160653,
      "state": "idle",
      "entity_id": "media_player.kitchen_display",
      "icon": "mdi:speaker",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "لما أوصل البيت",
      "context_message": "triggered",
      "context_entity_id": "automation.lm_wsl_lbyt"
    },
    {
      "when": 1715979714.161066,
      "state": "on",
      "entity_id": "media_player.alarm_siren",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "لما أوصل البيت",
      "context_message": "triggered",
      "context_entity_id": "automation.lm_wsl_lbyt"
    },
    {
      "when": 1715979716.417971,
      "state": "playing",
      "entity_id": "media_player.kitchen_display",
      "icon": "mdi:speaker",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "لما أوصل البيت",
      "context_message": "triggered",
      "context_entity_id": "automation.lm_wsl_lbyt"
    }
  ]
}

It seems that it’s working now. After I come home my wife told me that the light turned in the kitchen and the kitchen display announced welcome :slightly_smiling_face:.
But now I have to limit the automation to after the sunset. I will see if this will work