Automation/Device Issue

I’ve experienced odd behaviour with a specific automation/device on a number of occasions and was wondering if anyone else has experienced the same and found a fix for it.

I have an automation that opens blinds and turns off lights when a Hue light sensor is triggered above a lux value.

However, on occasion it doesn’t run when I feel like it is light enough outside that the lux level would have been met. So I open HA companion app or in browser to check the actual lux level and, mysteriously, the automation runs. It’s as if opening the HA app triggers the Hue sensor to poll for the lux level, whereas it should do this regardless?

Below is my automation if anyone has any advice or can point out any issues I’m not aware of.

- alias: Open Blinds
  id: open_blinds
  mode: single
  trigger:
    platform: numeric_state
    entity_id: sensor.master_bedroom_motion_sensor_illuminance
    above: 7
  condition:
  - condition: state
    entity_id: sun.sun
    attribute: rising
    state: true
  action:
  - service: script.open_downstairs_blinds
  - service: script.open_office_blinds

What does the state history of the luminance sensor look like? Is it the same value until the moment you open the app or has it been updating in the background? I’d say that’s the first place to check

- 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

I know you’ve posted this answer before (put criteria in triggers and conditions) but why do you have to do that in the first place? What does it change that putting your criteria in the trigger alone does not?

This is odd. The trigger is above 7lx. All night the sensor was 0lx, which is expected, then up to 4lx at 8:06. I opened my companion app at 8:14 and as soon as I did that the automation triggered…however, looking at the history the sensor stayed at 4lx until 2 minutes after the automation ran but that is 3lx less than the target level.

In the first post’s example, it will trigger the moment that illuminance increases above 7. The automation will execute its actions only if triggered after sunrise. What if it’s triggered before sunrise? Its actions are not executed and the automation won’t trigger again until illuminance first decreases below 7 and then increases above it. In other words, the blinds aren’t opened that morning.

Examine the automation’s trace that was produced at 8:14.

But doesn’t my existing condition do the same thing?

  condition:
  - condition: state
    entity_id: sun.sun
    attribute: rising
    state: true

You’re focusing on the wrong part of the problem. Based on your latest information, you should examine the automation’s trace to determine how it operated at 8:14.

Here’s the automation trace when it was triggered

image

That’s an overview of the trace. All it tells you is what you already know; the automation was triggered and executed its actions. You need to examine the triggering details.

The upper right corner of the trace view has a menu that offers to download the trace as a file. Post the contents of that file so we can examine it.

Oh yes I’d misread the OP and thought the sun and luminance were both triggers! Thanks :slight_smile:

Here’s the detailed trace:

{
  "trace": {
    "last_step": "sequence/0/0",
    "run_id": "f09384c9194552e5cceeb0f3e1fc7775",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-12-15T08:13:59.767914+00:00",
      "finish": "2023-12-15T08:14:01.396582+00:00"
    },
    "domain": "script",
    "item_id": "open_office_blinds",
    "trace": {
      "sequence/0": [
        {
          "path": "sequence/0",
          "timestamp": "2023-12-15T08:13:59.771366+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "script.open_office_blinds",
              "state": "off",
              "attributes": {
                "last_triggered": "2023-12-14T08:16:49.147052+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Open Office Blinds"
              },
              "last_changed": "2023-12-14T12:02:23.270073+00:00",
              "last_updated": "2023-12-14T12:02:23.270073+00:00",
              "context": {
                "id": "01HHM39PD6G8R7X5Z0Q25BYB4R",
                "parent_id": null,
                "user_id": null
              }
            },
            "context": {
              "id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
              "parent_id": "01HHP8M1FAMHFW0Z1GVCW5Q1XN",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "cover",
              "service": "set_cover_position",
              "service_data": {
                "position": 76,
                "entity_id": [
                  "cover.office_blinds_simple"
                ]
              },
              "target": {
                "entity_id": [
                  "cover.office_blinds_simple"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "sequence/0/0": [
        {
          "path": "sequence/0/0",
          "timestamp": "2023-12-15T08:13:59.777400+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "cover.office_blinds_simple",
              "state": "open",
              "attributes": {
                "current_position": 32,
                "device_class": "blind",
                "friendly_name": "Office Blinds (Simple)",
                "supported_features": 7
              },
              "last_changed": "2023-12-15T08:14:01.382530+00:00",
              "last_updated": "2023-12-15T08:32:44.595695+00:00",
              "context": {
                "id": "01HHP9PHHH9CT3ZWEN8SGC71DW",
                "parent_id": null,
                "user_id": null
              }
            },
            "position": 76
          },
          "result": {
            "params": {
              "domain": "cover",
              "service": "set_cover_tilt_position",
              "service_data": {
                "tilt_position": 38,
                "entity_id": [
                  "cover.office_blinds"
                ]
              },
              "target": {
                "entity_id": [
                  "cover.office_blinds"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "alias": "Open Office Blinds",
      "sequence": [
        {
          "service": "cover.set_cover_position",
          "target": {
            "entity_id": "cover.office_blinds_simple"
          },
          "data": {
            "position": 76
          }
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
      "parent_id": "01HHP8M1FAMHFW0Z1GVCW5Q1XN",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "when": 1702628039.768183,
      "state": "on",
      "entity_id": "script.open_office_blinds"
    },
    {
      "when": 1702628041.380492,
      "state": "opening",
      "entity_id": "cover.office_blinds",
      "context_state": "on",
      "context_entity_id": "script.open_office_blinds"
    },
    {
      "when": 1702628041.38253,
      "state": "open",
      "entity_id": "cover.office_blinds_simple",
      "context_state": "on",
      "context_entity_id": "script.open_office_blinds"
    },
    {
      "when": 1702628041.394475,
      "state": "off",
      "entity_id": "script.open_office_blinds",
      "context_state": "on",
      "context_entity_id": "script.open_office_blinds"
    },
    {
      "when": 1702628042.236691,
      "state": "59.0",
      "entity_id": "number.living_room_blinds_number",
      "icon": "phu:vert-blind-close",
      "context_state": "on",
      "context_entity_id": "script.open_office_blinds"
    },
    {
      "when": 1702628043.292958,
      "state": "73.0",
      "entity_id": "number.kitchen_blinds_number",
      "context_state": "on",
      "context_entity_id": "script.open_office_blinds"
    }
  ]
}

Is that a trace of the automation automation.open_blinds or a trace of the script script.open_office_blinds?

We need to see the automation’s trace.

1 Like

It is the automation trace. I selected the below then obtained the above trace to download

image

It’s not though.

{
  "trace": {
    "last_step": "action/1/choose/0/sequence/0",
    "run_id": "3b42756a710a39d5038b3e2123a781c3",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-12-15T14:31:05.017937+00:00",
      "finish": "2023-12-15T14:31:05.029746+00:00"
    },
    "domain": "automation",

This is what the start of a trace from an automation looks like.

And it has bits in in that show the triggers - like this:

      "trigger/1": [
        {
          "path": "trigger/1",
          "timestamp": "2023-12-15T14:31:05.017998+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.wfpi_controller",
              "state": "on",
              "attributes": {
                "id": "1688228731016",
                "last_triggered": "2023-12-15T14:26:05.537270+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "WFPi Controller"
              },

You need to go into the automation page, find the automation and click the 3 dots to open traces. Change to the time to the 8:13am one in the drop down and then click the 3 dots to download the trace.

“Open Blinds” is the script - which it is telling you is what was run. So the trace is for the script, not the automation that ran it (which is I admit very confusing)

1 Like

I didn’t realise. Thanks.

Correct trace:

{
  "trace": {
    "last_step": "action/1",
    "run_id": "c1b14e824df48da4244381de79761d4c",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-12-15T08:13:54.033907+00:00",
      "finish": "2023-12-15T08:14:01.399039+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-15T08:13:54.034034+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.open_blinds",
              "state": "on",
              "attributes": {
                "id": "open_blinds",
                "last_triggered": "2023-12-14T08:16:43.542078+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Open Blinds"
              },
              "last_changed": "2023-12-14T12:02:23.280461+00:00",
              "last_updated": "2023-12-14T12:02:23.280461+00:00",
              "context": {
                "id": "01HHM39PDGSM65GP9CQKSC3ESR",
                "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": 7413,
                  "unit_of_measurement": "lx",
                  "device_class": "illuminance",
                  "friendly_name": "Master Bedroom Motion Sensor Illuminance"
                },
                "last_changed": "2023-12-15T08:08:59.435879+00:00",
                "last_updated": "2023-12-15T08:08:59.435879+00:00",
                "context": {
                  "id": "01HHP8B1SBX6VENEWGNVJMQ7YY",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
                "state": "13",
                "attributes": {
                  "state_class": "measurement",
                  "light_level": 11392,
                  "unit_of_measurement": "lx",
                  "device_class": "illuminance",
                  "friendly_name": "Master Bedroom Motion Sensor Illuminance"
                },
                "last_changed": "2023-12-15T08:13:54.026255+00:00",
                "last_updated": "2023-12-15T08:13:54.026255+00:00",
                "context": {
                  "id": "01HHP8M1FAMHFW0Z1GVCW5Q1XN",
                  "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-15T08:13:54.034123+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2023-12-15T08:13:54.034201+00:00",
          "result": {
            "result": true,
            "state": true,
            "wanted_state": true
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-12-15T08:13:54.040261+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "open_downstairs_blinds",
            "run_id": "55cdae57f1c897163e672d2eae4a68c8"
          },
          "changed_variables": {
            "context": {
              "id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
              "parent_id": "01HHP8M1FAMHFW0Z1GVCW5Q1XN",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "open_downstairs_blinds",
              "service_data": {},
              "target": {}
            },
            "running_script": true
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-12-15T08:13:59.767166+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "open_office_blinds",
            "run_id": "f09384c9194552e5cceeb0f3e1fc7775"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "open_office_blinds",
              "service_data": {},
              "target": {}
            },
            "running_script": true
          }
        }
      ]
    },
    "config": {
      "alias": "Open Blinds",
      "id": "open_blinds",
      "mode": "single",
      "trigger": {
        "platform": "numeric_state",
        "entity_id": "sensor.master_bedroom_motion_sensor_illuminance",
        "above": 7
      },
      "condition": [
        {
          "condition": "state",
          "entity_id": "sun.sun",
          "attribute": "rising",
          "state": true
        }
      ],
      "action": [
        {
          "service": "script.open_downstairs_blinds"
        },
        {
          "service": "script.open_office_blinds"
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
      "parent_id": "01HHP8M1FAMHFW0Z1GVCW5Q1XN",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Open Blinds",
      "message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "entity_id": "automation.open_blinds",
      "context_id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
      "when": 1702628034.034492,
      "domain": "automation"
    },
    {
      "name": "Open Downstairs Blinds",
      "message": "started",
      "entity_id": "script.open_downstairs_blinds",
      "context_id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
      "when": 1702628034.040885,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628034.041246,
      "state": "on",
      "entity_id": "script.open_downstairs_blinds",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628035.038319,
      "state": "off",
      "entity_id": "light.xmas_tree_lights",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628035.063702,
      "state": "off",
      "entity_id": "light.living_room_lamp",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628035.070245,
      "state": "off",
      "entity_id": "light.cabinet",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628035.073661,
      "state": "off",
      "entity_id": "light.living_room_lights_all",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628035.074952,
      "state": "\"0\"",
      "entity_id": "sensor.lights_on_count",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628036.045761,
      "state": "on",
      "entity_id": "light.xmas_tree_lights",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628036.070366,
      "state": "on",
      "entity_id": "light.living_room_lights_all",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628039.049143,
      "state": "72.0",
      "entity_id": "number.kitchen_blinds_number",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628039.749335,
      "state": "58.0",
      "entity_id": "number.living_room_blinds_number",
      "icon": "phu:vert-blind-close",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "name": "Open Office Blinds",
      "message": "started",
      "entity_id": "script.open_office_blinds",
      "context_id": "01HHP8M1FHP8PMFQHX4PD6ZYXR",
      "when": 1702628039.767829,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628039.768183,
      "state": "on",
      "entity_id": "script.open_office_blinds",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628041.380492,
      "state": "opening",
      "entity_id": "cover.office_blinds",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628041.38253,
      "state": "open",
      "entity_id": "cover.office_blinds_simple",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628041.394475,
      "state": "off",
      "entity_id": "script.open_office_blinds",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628042.236691,
      "state": "59.0",
      "entity_id": "number.living_room_blinds_number",
      "icon": "phu:vert-blind-close",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    },
    {
      "when": 1702628043.292958,
      "state": "73.0",
      "entity_id": "number.kitchen_blinds_number",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Open Blinds",
      "context_message": "triggered by numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_source": "numeric state of sensor.master_bedroom_motion_sensor_illuminance",
      "context_entity_id": "automation.open_blinds"
    }
  ]
}
1 Like

It triggered normally. The illuminance value changed from 5 to 13.

1 Like

So we can see there that the illuminance changed from 5 to 13, which is why the automation triggered. I note however that it’s a motion sensor you are getting the illuminance value from - and just wanted to make you aware that typically these don’t update the illuminance value frequently, and often only update it periodically when motion was detected.

1 Like

@123 @mobile.andrew.jones Thanks both for your help.

So, it’s likely just pure coincidence that I open the app and the automation runs at the same time or that the app opening is forcing the polling of the entity?

@mobile.andrew.jones Totally get what you’re saying about the motion sensor capability as I’ve read about it before but I found it difficult to find any smart standalone light sensors available anywhere, unfortunately.