Newbie help on weird automation result

Hi there,

I didn’t found an introduction area, so I start right away. Apologies if I missed anything.

I’m new to HA and still learning. Reading a lot about it and having some limited background in home automation and programming in general.

Today something weird happend (at least for me) after I had a power outage and my Raspi HA went down uncontrolled. On restart one of my automations was fired but the conditions weren’t met, which turned my outdoor lights on after lunch.
I tried to figure out why that happend, probably because I made a mistake, but I don’t see why. Hope you experienced guys can help me with that proably easy question.

Here is my automation YAML:

trigger:
  - platform: numeric_state
    entity_id:
      - sun.sun
    attribute: elevation
    below: -5
condition:
  - condition: and
    conditions:
      - condition: time
        after: "16:00:00"
        before: "21:00:00"
      - condition: state
        entity_id: automation.lichtautomatik_ein_aus
        state: "on"
action:
  - type: turn_on
    device_id: x
    entity_id: y
    domain: switch
mode: restart

None of the conditions were met (beside the last one), so I’m wondering, why it was fired as it is an AND condition. From the recent run log I see HA recognized no condition was met, but fired it anyway.

Any idea please?

Thank you in advance

Dit the automation trace show it executed the action, or do you just conclude it did because the light went on?

A lot of smart lights have a default parameter to turn the light on after a power outage. So what could have happened is that the lights turned on by themselves, and HA noticed that on the restart.

From what I can see I would say it was triggered by automation, not by any default value of the device.https://1drv.ms/i/s!AioD9WohQDgKhNU4S5VyIbXv9KG4mg?e=3OFL1B

Check the automation’s trace. Specifically the trace when it executed its actions when you say it shouldn’t have.

Post the trace file so we can examine it.

Screenshot_20231117-152943~2

This screenshot looks like the automation was run “from the outside” and not from a trigger. So I think the automation was either run by the ui, a voice command or a service call to run it. If that happens, conditions are not evaluated. Could it be an other automation called this one?

Thanks for digging into this.
I checked other automations and I see another was fired as well without checking any condiotions, while another one was fired, but went through all conditions properly.
Hope the trace will help.https://1drv.ms/u/s!AioD9WohQDgKhNU5V_KHWZPB4KeL6w?e=TBb7hH

Your link requires that I log in with a Microsoft account in order to see the content.

Please post additional material (file, screenshots) directly in your post as opposed to elsewhere.

Lastly, please post the trace file, not a screenshot of some portion of the trace.

Well, I probably messed it up with Onedrive, because I didn’t found any option to upload JSON file here. I only found picture upload.
Interesting you are asked for a Microsoft account, because the link itself should grant access. I will review.
Hmm, tested the link in incognito window and it brings me directly to the file, without any prompt for MS account…

I’m not an expert at reading traces, but trigger platform null also suggests to me the automation was not run through a trigger, but started externally. My guess would be it was run as a script. That would explain the conditions not being evaluated, just need to figure now what called the automation.

{
  "trace": {
    "last_step": "action/0",
    "run_id": "57273de4703e7353c66b775f3e84484d",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-11-16T13:29:15.399052+00:00",
      "finish": "2023-11-16T13:29:16.315078+00:00"
    },
    "domain": "automation",
    "item_id": "1699288143850",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2023-11-16T13:29:15.399135+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.licht_einschalten_sonnenstand",
              "state": "on",
              "attributes": {
                "id": "1699288143850",
                "last_triggered": "2023-11-16T06:47:58.037143+00:00",
                "mode": "restart",
                "current": 0,
                "friendly_name": "Licht Haustuer einschalten abends"
              },
              "last_changed": "2023-11-16T13:28:46.922507+00:00",
              "last_updated": "2023-11-16T13:28:46.922507+00:00",
              "context": {
                "id": "01HFC53RJA6TBPVPFXTMR88HFS",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-11-16T13:29:15.399576+00:00",
          "changed_variables": {
            "context": {
              "id": "01HFC54MC6ZAG8Y4GEDGFSYD0Z",
              "parent_id": "01HFC54MBZ8RKHTA6HJKFNJT8H",
              "user_id": null
            }
          }
        }
      ]
    },
    "config": {
      "id": "1699288143850",
      "alias": "Licht Haustuer einschalten abends",
      "description": "",
      "trigger": [
        {
          "platform": "numeric_state",
          "entity_id": [
            "sun.sun"
          ],
          "attribute": "elevation",
          "below": -5
        }
      ],
      "condition": [
        {
          "condition": "and",
          "conditions": [
            {
              "condition": "time",
              "after": "16:00:00",
              "before": "21:00:00"
            },
            {
              "condition": "state",
              "entity_id": "automation.lichtautomatik_ein_aus",
              "state": "on"
            }
          ]
        }
      ],
      "action": [
        {
          "type": "turn_on",
          "device_id": "5f453e2828e0ce8b123600bf4e0e7c63",
          "entity_id": "4f51c00d849e4dde586d7604597c20d0",
          "domain": "switch"
        }
      ],
      "mode": "restart"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HFC54MC6ZAG8Y4GEDGFSYD0Z",
      "parent_id": "01HFC54MBZ8RKHTA6HJKFNJT8H",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Licht Haustuer einschalten abends",
      "message": "triggered",
      "source": null,
      "entity_id": "automation.licht_einschalten_sonnenstand",
      "context_id": "01HFC54MC6ZAG8Y4GEDGFSYD0Z",
      "when": 1700141355.399261,
      "domain": "automation"
    },
    {
      "when": 1700141356.307154,
      "state": "on",
      "entity_id": "switch.aussenlicht",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Licht Haustuer einschalten abends",
      "context_message": "triggered",
      "context_entity_id": "automation.licht_einschalten_sonnenstand"
    }
  ]
}

For future reference, simply copy-paste the file contents into the forum post. That’s what Edwin_d did with your linked file.

That’s why it’s inadvisable to post to external sources. In addition, at a later date, access to external contents may disappear thereby preventing future readers of a topic from seeing all related content.

Are you using the automation.trigger service call anywhere in some script or automation?


EDIT

Your automation contains a State Condition that checks if another automation is enabled. The implication is that sometimes that other automation is disabled. Do you possibly have automations that enable or disable other automations (or themselves)?

I do have an automation enabling and disable this automation, but it has conditions as well.
I restarted my Raspi to see if this automation would be triggered again during restart, but it did not.
Maybe it was triggered that day, because the system was restarted due to the power outage? So system state wasn’t clear, which might have messed up the automation?

Today I had a power outage again and everything came up normally, so it probably has been an one-time event.
Case closed for now :wink:

Thanks for your support.