Automation issue - No motion turn off power

Hi Guys,

I am struggling with this automation and can’t quite get it right.

I am looking to do the following:

When kitchen aqara motion occupancy and dining room aqara motion occupancy go from any state to clear for 5mins.

and if
Guest mode is OFF
Flip mode is OFF
the time is after 20.05 and before 23.59.59

Then
Switch off Day room TV power
Switch off day room Apple TV

Here is the yaml

- id: '1733086533701'
  alias: Day Room TV off if no motion TEST
  description: ''
  triggers:
  - entity_id:
    - binary_sensor.0x00158d000af2c00f_occupancy
    - binary_sensor.0x00158d000af2aae4_occupancy
    to: 'off'
    for:
      minutes: 5
    trigger: state
    from:
  conditions:
  - condition: state
    entity_id: input_boolean.guest_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.flip_mode
    state: 'off'
  - condition: time
    after: '20:05:00'
    before: '23:59:59'
  actions:
  - target:
      entity_id:
      - switch.panasonic_65_power
      - switch.apple_tv_dayroom_power
    action: switch.turn_off
    data: {}
  mode: single

This doesn’t seem to be working. Can you spot anything I am missing?

thanks,

Does it trigger? If so, post an automation trace (three dots, download trace, paste here as formatted code). The empty from: concerns me a bit: can you remove that?

Thanks for your reply.

It is not triggering. If I go to the 3 dots and click ‘Run Actions’ it turns off the relevant power sources though.

I have removed the ‘From’ from the yaml shown below.

- id: '1733086533701'
  alias: Day Room TV off if no motion TEST
  description: ''
  triggers:
  - entity_id:
    - binary_sensor.0x00158d000af2c00f_occupancy
    - binary_sensor.0x00158d000af2aae4_occupancy
    to: 'off'
    for:
      minutes: 5
    trigger: state
  conditions:
  - condition: state
    entity_id: input_boolean.guest_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.flip_mode
    state: 'off'
  - condition: time
    after: '12:05:00'
    before: '23:59:59'
  actions:
  - target:
      entity_id:
      - switch.panasonic_65_power
      - switch.apple_tv_dayroom_power
    action: switch.turn_off
    data: {}
  mode: single

OK, so you just need to wait for one of those binary sensors to go off and stay off for five minutes.

Have a look at the history graph for them — if they go unavailable at all, that will restart the timer.

They both go clear for some time.

I can’t see why this is not triggering. For the trigger, should I set ‘to’ to ‘Clear’ instead of ‘off’?

Actually, I have just checked the developer tools states and it is shown as on and off!

'on' and 'off' are correct to use in automations, not the “translated” Detected and Clear.

YAML looks fine assuming you have the entity IDs correct. How have you made this automation? The indentation doesn’t look like the UI has made it: I’ve just created one and it looks like this:

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.garage_motion
      - binary_sensor.utility_room_motion
    for:
      hours: 0
      minutes: 5
      seconds: 0
    to: "off"

Nothing wrong with yours per se nor with editing in YAML (which is what I do most of the time), but if you’re creating it manually with risky entity id names (starting 0x0) something else might have gone wrong.

Could you take a screenshot of the trigger section of the UI to see how that is interpreting it? Like this but with your entities:

image

1 Like

I can’t see why that’s not triggering. Definitely no traces available?

Looks like I have traces…

{
  "trace": {
    "last_step": "action/0",
    "run_id": "39cc1394c07668b573c9e344595c9eb1",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-12-13T14:06:20.545930+00:00",
      "finish": "2024-12-13T14:06:20.566196+00:00"
    },
    "domain": "automation",
    "item_id": "1733086533701",
    "trigger": "state of binary_sensor.0x00158d000af2aae4_occupancy",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-12-13T14:06:20.546091+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.day_room_tv_no_motion_test",
              "state": "on",
              "attributes": {
                "id": "1733086533701",
                "last_triggered": "2024-12-13T14:01:46.509295+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Day Room TV off if no motion TEST"
              },
              "last_changed": "2024-12-13T13:55:50.371687+00:00",
              "last_reported": "2024-12-13T14:01:46.533154+00:00",
              "last_updated": "2024-12-13T14:01:46.533154+00:00",
              "context": {
                "id": "01JF056MRB3G5E99MT4BAJN159",
                "parent_id": "01JF04XFRP47V8HPFD4CMP6P1T",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "binary_sensor.0x00158d000af2aae4_occupancy",
              "from_state": {
                "entity_id": "binary_sensor.0x00158d000af2aae4_occupancy",
                "state": "on",
                "attributes": {
                  "device_class": "occupancy",
                  "friendly_name": "Dining Room Aqara Motion Occupancy"
                },
                "last_changed": "2024-12-13T13:59:50.534383+00:00",
                "last_reported": "2024-12-13T13:59:50.534383+00:00",
                "last_updated": "2024-12-13T13:59:50.534383+00:00",
                "context": {
                  "id": "01JF0533G66KVS8940J9RB6968",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.0x00158d000af2aae4_occupancy",
                "state": "off",
                "attributes": {
                  "device_class": "occupancy",
                  "friendly_name": "Dining Room Aqara Motion Occupancy"
                },
                "last_changed": "2024-12-13T14:01:20.542923+00:00",
                "last_reported": "2024-12-13T14:01:20.542923+00:00",
                "last_updated": "2024-12-13T14:01:20.542923+00:00",
                "context": {
                  "id": "01JF055VCY0EVF0S9YX7B61QGA",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 300
              },
              "attribute": null,
              "description": "state of binary_sensor.0x00158d000af2aae4_occupancy"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2024-12-13T14:06:20.546217+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/0/entity_id/0": [
        {
          "path": "condition/0/entity_id/0",
          "timestamp": "2024-12-13T14:06:20.546316+00:00",
          "result": {
            "result": true,
            "state": "off",
            "wanted_state": "off"
          }
        }
      ],
      "condition/1": [
        {
          "path": "condition/1",
          "timestamp": "2024-12-13T14:06:20.546545+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/1/entity_id/0": [
        {
          "path": "condition/1/entity_id/0",
          "timestamp": "2024-12-13T14:06:20.546630+00:00",
          "result": {
            "result": true,
            "state": "off",
            "wanted_state": "off"
          }
        }
      ],
      "condition/2": [
        {
          "path": "condition/2",
          "timestamp": "2024-12-13T14:06:20.546806+00:00",
          "result": {
            "after": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "12:05:00"
            },
            "now_time": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "14:06:20.546857"
            },
            "before": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "23:59:59"
            },
            "result": true
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-12-13T14:06:20.548330+00:00",
          "changed_variables": {
            "context": {
              "id": "01JF05F0C1976NY5G7HJWPVM2B",
              "parent_id": "01JF055VCY0EVF0S9YX7B61QGA",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "switch.panasonic_65_power",
                  "switch.apple_tv_dayroom_power"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1733086533701",
      "alias": "Day Room TV off if no motion TEST",
      "description": "",
      "triggers": [
        {
          "entity_id": [
            "binary_sensor.0x00158d000af2c00f_occupancy",
            "binary_sensor.0x00158d000af2aae4_occupancy"
          ],
          "to": "off",
          "for": {
            "minutes": 5
          },
          "trigger": "state"
        }
      ],
      "conditions": [
        {
          "condition": "state",
          "entity_id": "input_boolean.guest_mode",
          "state": "off"
        },
        {
          "condition": "state",
          "entity_id": "input_boolean.flip_mode",
          "state": "off"
        },
        {
          "condition": "time",
          "after": "12:05:00",
          "before": "23:59:59"
        }
      ],
      "actions": [
        {
          "target": {
            "entity_id": [
              "switch.panasonic_65_power",
              "switch.apple_tv_dayroom_power"
            ]
          },
          "action": "switch.turn_off",
          "data": {}
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01JF05F0C1976NY5G7HJWPVM2B",
      "parent_id": "01JF055VCY0EVF0S9YX7B61QGA",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Day Room TV off if no motion TEST",
      "message": "triggered by state of binary_sensor.0x00158d000af2aae4_occupancy",
      "source": "state of binary_sensor.0x00158d000af2aae4_occupancy",
      "entity_id": "automation.day_room_tv_no_motion_test",
      "context_id": "01JF05F0C1976NY5G7HJWPVM2B",
      "domain": "automation",
      "when": 1734098780.5470948
    }
  ]
}

That looks like it worked: triggered off no motion from the dining room sensor, passed the two toggle and one time conditions, and appears to have run the action.

Very odd…Let me check the end devices.

It’s just started working!

Something you changed has worked!

Well, thank you Troon, much appreciated :grinning:

1 Like