Motion Sensor and Shelly 1 Switch

Hi all,

I have been racking my brain and I am new to this however I have got several things working and this one baffles me.

In short i have a internal motion sensor connected a shelly 1, the sensor goes ‘on’ and my automation begins, the light turns on for 13 seconds and then turns off. It also has a condition being that if the switch on the dashboard is turned on then the automation wont work, essentially creating a master override for permanent light on.

The problem is the shelly 1 has a binary sensor which confirms if the ‘input sensor’ has received power from the motion sensor, creating the ‘on’ and ‘off’ status which stops my automation for staying on for longer. Say i pass through the hallway the sensor lights up the hallway for 13 seconds, brilliant but just in case i am in the hallway vacuuming then the light still turns on after 13 seconds. I need to somehow incorporate a line that says 'if the sensor is ‘on’ then the light will stay on until the sensor goes to ‘off’ when no motion is detected. so walking through hallway 13 seconds is acceptable but longer time in the hallway means the light should turn off after i leave, say 13 seconds after or even 3 seconds to be perfect.

here is my code below, i have used the automation section via configuration not coding so please understand my knowledge around coding is limited.

alias: Master Downstairs Hallway
description: ‘’
trigger:

  • platform: state
    entity_id: binary_sensor.shelly1_cx_input
    from: ‘off’
    to: ‘on’
    for:
    hours: 0
    minutes: 0
    seconds: 0
    milliseconds: 0
    condition:
  • condition: device
    type: is_off
    device_id: DELETED THIS AS NOT SURE IF IT IS SAFE TO DISPLAY
    entity_id: switch.shelly1_cx
    domain: switch
    action:
  • type: turn_on
    device_id: DELETED THIS AS NOT SURE IF IT IS SAFE TO DISPLAY
    entity_id: switch.shelly1_cx
    domain: switch
  • delay:
    hours: 0
    minutes: 0
    seconds: 13
    milliseconds: 0
  • type: turn_off
    device_id: DELETED THIS AS NOT SURE IF IT IS SAFE TO DISPLAY
    entity_id: switch.shelly1_cx
    domain: switch
    mode: single

any help would be appreciated, i end up in the dark sometimes and then have to walk to another room turn on the light via an ipad dashboard.

Thank you in advance.

No need to reply, managed to fixed it myself with trial and error.