Motion Sensor Lights not working

Hi, I have the stock standard motion-activated light automation in HA and recently it’s been hit and miss with when it works and doesn’t work.

Lights - I have Shelly switches connected to my light switches and through HA all working through Shelly app.

Motion Sensors - I use Sonoff Zigbee motion sensors connected through HA all working through Tuya App.

Can anyone tell me why it’s hit and miss? I have 3 x motion sensors that set off 3 different lights, I’ve noticed when one isn’t working, all of them aren’t.

If anyone else has a better way to do motion sensor lights or can point me in the right direction, I’d love to know. Or if you can fix this? I use them in my pantry, walking in linen and walk in robe, because otherwise my wife leaves them on. So I want them to come on with motion and go off at a set time.

There is no stock automations in HA, so please show the yaml code.

It might be obvious to you, but not to us.
What doesn’t work? Is motion detected but light not turned on? Is motion not detected? Is the automation not triggered?
If the automation is triggered, please provide traces.

Bottom-line: I, personally, would probably not be able to help you, but please give yourself a chance to get an answer by providing enough information in your initial post.
Not everyone (few, actually) are willing to spend time extracting the needed information from you.

You might have a look at Entity Controller in HACS. It replaces lengthy automations with just a few lines of yaml. For example:

  - living_room_light:                               
      sensor: 
      - binary_sensor.living_room_motion_sensor
      entities: 
      - switch.living_room_socket_1
      - switch.living_room_socket_4
      delay: 600
      block_timeout: 600
      overrides: 
      - binary_sensor.override_indoor_front

This turns on two lamps when motion is detected and leaves them on for 10 minutes. If someone turns on one of the lights manually, it will also leave it on for 10 minutes. If the light level in the room is sufficient not to need a light, they don’t come on.

Hi, thanks for taking the time to reply. Sorry I don’t know the slang, stock standard should read blueprint.
The code, when you create an automation using the blueprint.

- id: '1665838976207'
  alias: Auto Pantry
  description: ''
  use_blueprint:
    path: homeassistant/motion_light.yaml
    input:
      motion_entity: binary_sensor.pir_motion_sensor_2
      light_target:
        area_id: pantry
        entity_id: light.shelly1pm_98cdac1ed80c
      no_motion_wait: 5

Blueprint below:

blueprint:
  name: Motion-activated Light
  description: Turn on a light when motion is detected.
  domain: automation
  source_url: https://github.com/home-assistant/core/blob/66b105fb21ac7d2c0250f792faa924109961489d/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target

So motion is detected, but light doesn’t turn on. Yet I can go into the app or HA and use buttons to manually turn this lights on, suggesting it’s the automation not the connectivity with the devices. Hence, automation not triggered.

did you resolve this? stuck at very similar step also with shelly +1 switches