Why did this automation trigger when the conditions were not met?

The trace clearly shows that conditions/0/conditions/0 is false and so is conditions/0/conditions/1 yet the expected result was still true?

This is a simple automation that turns on my LG C1 TV when my computer turns on (I use a TV as a monitor), yet it instead turned off my TV.

Any help would be appreciated. Thanks

it’s pretty hard to examine things via images.

could you grab the download trace and post that as well as post the original automation?

Here’s the trace of the downloaded trace:

{
  "trace": {
    "last_step": "action/0/choose/1/sequence/0",
    "run_id": "129357155f93754bb07ca59ea48dc5bc",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-09-29T18:51:33.604966+00:00",
      "finish": "2024-09-29T18:51:33.607407+00:00"
    },
    "domain": "automation",
    "item_id": "1698706303366",
    "trigger": "state of switch.13900k",
    "trace": {
      "trigger/3": [
        {
          "path": "trigger/3",
          "timestamp": "2024-09-29T18:51:33.605147+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.ben_room_lg48c1",
              "state": "on",
              "attributes": {
                "id": "1698706303366",
                "last_triggered": "2024-09-29T18:48:34.599833+00:00",
                "mode": "restart",
                "current": 0,
                "friendly_name": "Ben Room LG48C1"
              },
              "last_changed": "2024-09-25T01:36:46.540079+00:00",
              "last_reported": "2024-09-29T18:48:34.601579+00:00",
              "last_updated": "2024-09-29T18:48:34.601579+00:00",
              "context": {
                "id": "01J8ZHSWH7HVF4XS0WM598AXT7",
                "parent_id": "01J8ZHSWH7GDA3AXJX3912M0ZJ",
                "user_id": null
              }
            },
            "trigger": {
              "id": "Computer on",
              "idx": "3",
              "alias": null,
              "platform": "state",
              "entity_id": "switch.13900k",
              "from_state": {
                "entity_id": "switch.13900k",
                "state": "off",
                "attributes": {
                  "friendly_name": "13900K"
                },
                "last_changed": "2024-09-29T18:48:34.599501+00:00",
                "last_reported": "2024-09-29T18:48:34.599501+00:00",
                "last_updated": "2024-09-29T18:48:34.599501+00:00",
                "context": {
                  "id": "01J8ZHSWH7GDA3AXJX3912M0ZJ",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "switch.13900k",
                "state": "on",
                "attributes": {
                  "friendly_name": "13900K"
                },
                "last_changed": "2024-09-29T18:51:33.604835+00:00",
                "last_reported": "2024-09-29T18:51:33.604835+00:00",
                "last_updated": "2024-09-29T18:51:33.604835+00:00",
                "context": {
                  "id": "01J8ZHZBB4XAJVNAWKB9EDJ0WA",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of switch.13900k"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-09-29T18:51:33.605555+00:00",
          "changed_variables": {
            "context": {
              "id": "01J8ZHZBB4N0WY2T0RW72HES2F",
              "parent_id": "01J8ZHZBB4XAJVNAWKB9EDJ0WA",
              "user_id": null
            }
          },
          "result": {
            "choice": 1
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2024-09-29T18:51:33.605614+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2024-09-29T18:51:33.605637+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/0/conditions/1": [
        {
          "path": "action/0/choose/0/conditions/1",
          "timestamp": "2024-09-29T18:51:33.605665+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/1/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/1/entity_id/0",
          "timestamp": "2024-09-29T18:51:33.605689+00:00",
          "result": {
            "result": false,
            "state": "on",
            "wanted_state": "off"
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2024-09-29T18:51:33.605738+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2024-09-29T18:51:33.605766+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/0",
          "timestamp": "2024-09-29T18:51:33.605784+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/1": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/1",
          "timestamp": "2024-09-29T18:51:33.605807+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/2": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/2",
          "timestamp": "2024-09-29T18:51:33.605827+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/2/entity_id/0": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/2/entity_id/0",
          "timestamp": "2024-09-29T18:51:33.605845+00:00",
          "result": {
            "result": true,
            "state": "on",
            "wanted_state": "on"
          }
        }
      ],
      "action/0/choose/1/sequence/0": [
        {
          "path": "action/0/choose/1/sequence/0",
          "timestamp": "2024-09-29T18:51:33.605961+00:00",
          "result": {
            "params": {
              "domain": "media_player",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "media_player.lg_48_c1"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1698706303366",
      "alias": "Ben Room LG48C1",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.ben_room_fp1_group"
          ],
          "from": "off",
          "to": "on",
          "id": "Ben Occupied"
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.ben_room_fp1_group"
          ],
          "from": "on",
          "to": "off",
          "id": "Ben Not Occupied",
          "for": {
            "hours": 0,
            "minutes": 5,
            "seconds": 0
          }
        },
        {
          "platform": "state",
          "entity_id": [
            "switch.13900k"
          ],
          "from": "on",
          "to": "off",
          "id": "Computer off"
        },
        {
          "platform": "state",
          "entity_id": [
            "switch.13900k"
          ],
          "from": "off",
          "to": "on",
          "id": "Computer on"
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.ben_room_fp1_group"
          ],
          "from": "off",
          "to": "on",
          "id": "Ben Occupied 1s",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 1
          }
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.ben_room_fp1_group"
          ],
          "from": "off",
          "to": "on",
          "id": "Ben Occupied 2s",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          }
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "Ben Occupied",
                    "Computer on",
                    "Ben Occupied 1s",
                    "Ben Occupied 2s"
                  ]
                },
                {
                  "condition": "state",
                  "entity_id": "binary_sensor.lg_c1_48_power_helper",
                  "state": "off"
                }
              ],
              "sequence": [
                {
                  "service": "wake_on_lan.send_magic_packet",
                  "data": {
                    "broadcast_port": 9,
                    "mac": "d4:86:60:1b:56:a6",
                    "broadcast_address": "10.10.20.229"
                  },
                  "enabled": true
                },
                {
                  "service": "remote.send_command",
                  "target": {
                    "entity_id": "remote.rm4_ben_room"
                  },
                  "data": {
                    "device": "LGC148",
                    "command": "power"
                  },
                  "enabled": false
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "or",
                  "conditions": [
                    {
                      "condition": "trigger",
                      "id": [
                        "Ben Not Occupied"
                      ]
                    },
                    {
                      "condition": "trigger",
                      "id": [
                        "Computer off"
                      ]
                    },
                    {
                      "condition": "state",
                      "entity_id": "binary_sensor.lg_c1_48_power_helper",
                      "state": "on"
                    }
                  ]
                }
              ],
              "sequence": [
                {
                  "service": "media_player.turn_off",
                  "data": {},
                  "target": {
                    "entity_id": "media_player.lg_48_c1"
                  }
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "restart"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01J8ZHZBB4N0WY2T0RW72HES2F",
      "parent_id": "01J8ZHZBB4XAJVNAWKB9EDJ0WA",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Ben Room LG48C1",
      "message": "triggered by state of switch.13900k",
      "source": "state of switch.13900k",
      "entity_id": "automation.ben_room_lg48c1",
      "context_id": "01J8ZHZBB4N0WY2T0RW72HES2F",
      "when": 1727635893.6052027,
      "domain": "automation"
    },
    {
      "when": 1727635897.596213,
      "state": "off",
      "entity_id": "media_player.lg_48_c1",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Ben Room LG48C1",
      "context_message": "triggered by state of switch.13900k",
      "context_source": "state of switch.13900k",
      "context_entity_id": "automation.ben_room_lg48c1"
    }
  ]
}

Here’s the automation:

alias: Ben Room LG48C1
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.ben_room_fp1_group
    from: "off"
    to: "on"
    id: Ben Occupied
  - platform: state
    entity_id:
      - binary_sensor.ben_room_fp1_group
    from: "on"
    to: "off"
    id: Ben Not Occupied
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - platform: state
    entity_id:
      - switch.13900k
    from: "on"
    to: "off"
    id: Computer off
  - platform: state
    entity_id:
      - switch.13900k
    from: "off"
    to: "on"
    id: Computer on
  - platform: state
    entity_id:
      - binary_sensor.ben_room_fp1_group
    from: "off"
    to: "on"
    id: Ben Occupied 1s
    for:
      hours: 0
      minutes: 0
      seconds: 1
  - platform: state
    entity_id:
      - binary_sensor.ben_room_fp1_group
    from: "off"
    to: "on"
    id: Ben Occupied 2s
    for:
      hours: 0
      minutes: 0
      seconds: 2
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Ben Occupied
              - Computer on
              - Ben Occupied 1s
              - Ben Occupied 2s
          - condition: state
            entity_id: binary_sensor.lg_c1_48_power_helper
            state: "off"
        sequence:
          - service: wake_on_lan.send_magic_packet
            data:
              broadcast_port: 9
              mac: d4:86:60:1b:56:a6
              broadcast_address: 10.10.20.229
            enabled: true
          - service: remote.send_command
            target:
              entity_id: remote.rm4_ben_room
            data:
              device: LGC148
              command: power
            enabled: false
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id:
                  - Ben Not Occupied
              - condition: trigger
                id:
                  - Computer off
              - condition: state
                entity_id: binary_sensor.lg_c1_48_power_helper
                state: "on"
        sequence:
          - service: media_player.turn_off
            data: {}
            target:
              entity_id: media_player.lg_48_c1
    default: []
mode: restart

Are you sure that switch.13900k didnt change the state to on?

ok. thanks for posting those.

i’m not sure what you expected to happen, but i can explain what i see and we can go from there…

in your first condition:

      - conditions:
          - condition: trigger
            id:
              - Ben Occupied
              - Computer on
              - Ben Occupied 1s
              - Ben Occupied 2s
          - condition: state
            entity_id: binary_sensor.lg_c1_48_power_helper
            state: "off"

the binary_sensor.lg_c1_48_power_helper was on. so this condition failed. here’s the relevant part:

     "action/0/choose/0/conditions/1/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/1/entity_id/0",
          "timestamp": "2024-09-29T18:51:33.605689+00:00",
          "result": {
            "result": false,
            "state": "on",
            "wanted_state": "off"
          }
        }

in the second condition, it succeeded because the that same sensor was on, and your condition asked for it to be on:

              - condition: state
                entity_id: binary_sensor.lg_c1_48_power_helper
                state: "on"

here’s the relevant part of the trace:

      "action/0/choose/1/conditions/0/conditions/2/entity_id/0": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/2/entity_id/0",
          "timestamp": "2024-09-29T18:51:33.605845+00:00",
          "result": {
            "result": true,
            "state": "on",
            "wanted_state": "on"
          }
        }
      ],

you said:

i presume you mean this about the second choose. if so, the reason is because you have an “or” wrapping the those two conditions such that if any one of the conditions being true makes the overall condition true:

### this "or"s the subsequent conditions together.
         - condition: or
###
            conditions:
              - condition: trigger
                id:
                  - Ben Not Occupied
              - condition: trigger
                id:
                  - Computer off
              - condition: state
                entity_id: binary_sensor.lg_c1_48_power_helper
                state: "on"

Ahh yes, I totally forgot it’s an or condition. I’ll move to test the condition in the action part!

Thank you so much! I can’t believe that slipped my mind.

Problem solved!

1 Like