Automation/Device Issue

If you don’t know the difference between an automation and a script, I recommend you review the following documentation:

Automation Basics
Scripts

The main difference is that an automation has triggers and a script doesn’t. Both support the production of traces in order to examine their operation in detail.

:smile: I meant I didn’t know where to obtain the correct trace. I was going via the logbook as I didn’t realise I had to go into Settings > Automations

That’s what’s called a misleading clue (a ‘red herring’).

All of this has been a diversion from the original question which was why the automation sometimes failed to open the blinds.

I suggest you try the enhanced version I posted earlier.

1 Like

If you are opening it in the bedroom - it’s possible that the light from the phone is enough to take the illuminance level high enough, and it’s just a co-incidence that you are checking the app - but really it’s just the bright light from the phone - and would happen whatever app you opened. You are after all trying to trigger this to open blinds in a room that is dark, because the blinds are closed.

I’ve amended it already. Thanks.

No, I’m opening the app in a totally remote area, and the sensor points externally out of the window

1 Like

Well the one big clue we have is that the illuminance jumped from 5 to 11. That’s quite a jump. So it gives us an idea, how infrequently it updates (but in any case Home Assistant does not poll any devices when you open the app, or load the website. Any polling is done behind the scenes on a fixed schedule regardless of whether the UI is open or not. And in the cases of Zigbee/ZWave/Thread etc - updates are pushed TO Home Assistant, not polled)

1 Like

I tried this but it failed to run this morning.

This is the trace:

{
  "trace": {
    "last_step": "condition/0/entity_id/0",
    "run_id": "0197282ed3a29791c0258e7b1b4163e6",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2023-12-16T07:54:38.505555+00:00",
      "finish": "2023-12-16T07:54:38.506270+00:00"
    },
    "domain": "automation",
    "item_id": "open_blinds",
    "trigger": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2023-12-16T07:54:38.505717+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.open_blinds",
              "state": "on",
              "attributes": {
                "id": "open_blinds",
                "last_triggered": "2023-12-15T08:13:54.034549+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Open Blinds"
              },
              "last_changed": "2023-12-15T14:16:09.105433+00:00",
              "last_updated": "2023-12-15T14:16:09.105433+00:00",
              "context": {
                "id": "01HHPXBB4H405K5CFQ5H2T2DHF",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "numeric_state",
              "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
              "below": null,
              "above": 7,
              "from_state": {
                "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
                "state": "5",
                "attributes": {
                  "state_class": "measurement",
                  "light_level": 7666,
                  "unit_of_measurement": "lx",
                  "device_class": "illuminance",
                  "friendly_name": "Master Bedroom Motion Sensor Illuminance"
                },
                "last_changed": "2023-12-16T07:49:44.033186+00:00",
                "last_updated": "2023-12-16T07:49:44.033186+00:00",
                "context": {
                  "id": "01HHRSMGF1W8XYYJVM3SPTYCVV",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
                "state": "11",
                "attributes": {
                  "state_class": "measurement",
                  "light_level": 10676,
                  "unit_of_measurement": "lx",
                  "device_class": "illuminance",
                  "friendly_name": "Master Bedroom Motion Sensor Illuminance"
                },
                "last_changed": "2023-12-16T07:54:38.455719+00:00",
                "last_updated": "2023-12-16T07:54:38.455719+00:00",
                "context": {
                  "id": "01HHRSXFZQTBECFSDGNC3YRQCP",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "description": "numeric state of sensor.master_bedroom_motion_sensor_illuminance"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2023-12-16T07:54:38.505861+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2023-12-16T07:54:38.506017+00:00",
          "result": {
            "result": false,
            "state": "below_horizon",
            "wanted_state": "above_horizon"
          }
        }
      ]
    },
    "config": {
      "alias": "Open Blinds",
      "id": "open_blinds",
      "mode": "single",
      "trigger": [
        {
          "platform": "numeric_state",
          "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
          "above": 7
        },
        {
          "platform": "sun",
          "event": "sunrise"
        }
      ],
      "condition": [
        {
          "condition": "state",
          "entity_id": "sun.sun",
          "state": "above_horizon"
        },
        {
          "condition": "numeric_state",
          "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
          "above": 7
        }
      ],
      "action": [
        {
          "service": "script.open_downstairs_blinds"
        },
        {
          "service": "script.open_office_blinds"
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HHRSXG197A33ED2ZBCGX4P3V",
      "parent_id": "01HHRSXFZQTBECFSDGNC3YRQCP",
      "user_id": null
    }
  },
  "logbookEntries": []
}

That trace shows the automation was triggered at 07:54 by the Numeric State Trigger. The illuminance had increased from 5 to 11, crossing the threshold of 7, so it triggered the automation.

However, the first condition, the Sun Condition, evaluated to false because the sun’s state was still below_horizon. The automation is designed to operate only between sunrise and sunset so that’s why it didn’t execute its actions.

When is sunrise at your location? The automation should have also triggered at sunrise and produced another trace.