Turn everything off once there's been no motion for 30 minutes and after 11p

Can’t quite get there. It keeps turning off at 11p, even though there’s been motion in the last 30min.

alias: Turn off Public Spaces at 11pm after 30min no motion
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.public_inside_motion
    to: "off"
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition:
  - condition: time
    before: "06:00:00"
    after: "23:00:00"
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.public_switches
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.public_bulbs
  - service: fan.turn_off
    data: {}
    target:
      entity_id: fan.public_fans
mode: single

It would be easier to diagnose what is going on if you would also provide the automation trace

Shouldn’t the trigger be the time, and the condition no motion for 30 min?

Trace

{
  "trace": {
    "last_step": "condition/0",
    "run_id": "1302c7db0a0171a6f7f031b151ddff99",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2022-09-20T14:19:01.414255+00:00",
      "finish": "2022-09-20T14:19:01.414727+00:00"
    },
    "domain": "automation",
    "item_id": "1663560699154",
    "trigger": "state of binary_sensor.public_inside_motion",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-09-20T14:19:01.414474+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.turn_off_at_1115",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-09-20T08:24:19.949324+00:00",
                "mode": "single",
                "current": 0,
                "id": "1663560699154",
                "friendly_name": "Turn off Public Spaces at 11pm after 30min no motion"
              },
              "last_changed": "2022-09-20T01:58:26.238013+00:00",
              "last_updated": "2022-09-20T08:24:24.492375+00:00",
              "context": {
                "id": "01GDCZYZQC7K85WBE5Y3HZ8B7B",
                "parent_id": "01GDCY81X5CYGM15PBBNVBS863",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "binary_sensor.public_inside_motion",
              "from_state": {
                "entity_id": "binary_sensor.public_inside_motion",
                "state": "on",
                "attributes": {
                  "entity_id": [
                    "binary_sensor.den_motion_iaszone",
                    "binary_sensor.dining_room_motion_iaszone",
                    "binary_sensor.gameroom_motion_iaszone",
                    "binary_sensor.kitchen_motion_iaszone",
                    "binary_sensor.office_motion_iaszone"
                  ],
                  "friendly_name": "Public Inside Motion"
                },
                "last_changed": "2022-09-20T13:47:54.850866+00:00",
                "last_updated": "2022-09-20T13:47:54.850866+00:00",
                "context": {
                  "id": "01GDDJFFK08YY3TMNP6N8KK9YG",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.public_inside_motion",
                "state": "off",
                "attributes": {
                  "entity_id": [
                    "binary_sensor.den_motion_iaszone",
                    "binary_sensor.dining_room_motion_iaszone",
                    "binary_sensor.gameroom_motion_iaszone",
                    "binary_sensor.kitchen_motion_iaszone",
                    "binary_sensor.office_motion_iaszone"
                  ],
                  "friendly_name": "Public Inside Motion"
                },
                "last_changed": "2022-09-20T13:49:01.410953+00:00",
                "last_updated": "2022-09-20T13:49:01.410953+00:00",
                "context": {
                  "id": "01GDDJHGK0REZRVMKDP8DS11FQ",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 1800
              },
              "attribute": null,
              "description": "state of binary_sensor.public_inside_motion"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2022-09-20T14:19:01.414589+00:00",
          "result": {
            "after": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "23:00:00"
            },
            "now_time": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "09:19:01.414630"
            },
            "before": {
              "__type": "<class 'datetime.time'>",
              "isoformat": "06:00:00"
            },
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1663560699154",
      "alias": "Turn off Public Spaces at 11pm after 30min no motion",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.public_inside_motion"
          ],
          "to": "off",
          "for": {
            "hours": 0,
            "minutes": 30,
            "seconds": 0
          }
        }
      ],
      "condition": [
        {
          "condition": "time",
          "before": "06:00:00",
          "after": "23:00:00"
        }
      ],
      "action": [
        {
          "service": "switch.turn_off",
          "data": {},
          "target": {
            "entity_id": "switch.public_switches"
          }
        },
        {
          "service": "light.turn_off",
          "data": {},
          "target": {
            "entity_id": "light.public_bulbs"
          }
        },
        {
          "service": "fan.turn_off",
          "data": {},
          "target": {
            "entity_id": "fan.public_fans"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01GDDM8ED6A0GGKB9JZGRGNCE0",
      "parent_id": "01GDDJHGK0REZRVMKDP8DS11FQ",
      "user_id": null
    }
  },
  "logbookEntries": []
}```

I didn’t want to only trigger once. I want everything to turn off once there’s no motion for 30 minutes anytime after 11p. I think if I trigger at a time, it would only do it once, right?

That’s why. When this automation triggered, it was NOT before 6am or after 11pm. it was 9:19am

Yeah, that’s because it was the most recent trace. I’ve had this running for about a week, so at some point it’s been between 2300 and 0600. See anything else in there that might be the cause?

I get that. But we won’t be able to help you diagnose the problem until you can post a trace of it not doing what it is supposed to.

My hunch - is that your public motion sensor, is a template sensor or sensor group - made up of multiple actual motion sensors?

I’ll update and post. and Yes, it’s made up of several sensors.

The solution was to set automation mode to restart

I’m curious, why’s that? I don’t expect restart mode is the solution.

I had it set to single mode, so once the no motion trigger was satisfied, the timer started for the turn of sequence regardless if motion was subsequently detected. Setting the mode to restart allows for a reseting of the timer if motion was detected after the original no motion detected trigger.