Entrance Gate - Kids safety

Hi all,

It would be Great to get some help from you regarding my new automation:

Enclosed you See photos of My Garden and my current automation which is not working.

  1. Aqara contact sensor
  2. hue Outdoor Motion Sensor
    (3) Shelly 1 in Motor of the Gate

A)
If state from (1)Switches from closed to open
B)
Please Check if (2) detected Last 5 sec or Next 20 motion: of yes:
C) toggle the shelly → gate stops
D) Wait 3 sec
E) toggle the shelly again → gate will Go back to „closed“

Unfortunatelly step 1 is Not Wirkung yet, therefore I was Not trying the Next actions.

Maybe you also have Some Other ideas to automate this Secure automation?

If everything works, I would do the same automation for *door wents From Open to closed“. Here I would an additional aqara Sensor.

Unfortunatelly I am Not allowed to add More than 1 picture

Regards
Arnold

Please don’t post pictures of text. Post the text and format it correctly (see point 11 here).

That way we can copy/paste/edit your config rather than typing it all out.

I will Upload it tomorrow. Unfortunatelly its not possible to copy Paste it With iPhone :persevere:

But then I use this post in order to show you my components.

alias: Schiebetor Sicherung (Duplicate)
description: >-
If the state is open, please check for the last 5 sec and the next 20 sec if
motions sensor is detecting anything. If triggered, pleas toggle shelly.
trigger:

  • platform: state
    entity_id: switch.shelly1
    to: open
    from: closed
    condition:
  • type: is_motion
    condition: device
    device_id: 38a7
    entity_id: binary_sensor.terasse_eingang_on_off
    domain: binary_sensor
    for:
    hours: 0
    minutes: 0
    seconds: 20
    milliseconds: 0
    action:
  • type: toggle
    device_id: b907
    entity_id: switch.shelly1
    domain: switch
  • wait_template: ‘00:00:03’
  • type: toggle
    device_id: b907
    entity_id: switch.shelly1
    domain: switch
    mode: restart

Please format your post correctly.

alias: Schiebetor Sicherung (Duplicate)
description: >-
  If the state is open, please check for the last 5 sec and the next 20 sec if
  motions sensor is detecting anything. If triggered, pleas toggle shelly.
trigger:
  - platform: state
    entity_id: switch.shelly1_e8db84d2f87b
    to: open
    from: closed
condition:
  - type: is_motion
    condition: device
    device_id: 38a7d42dddeea5234579167146c2c2af
    entity_id: binary_sensor.terasse_eingang_on_off
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
action:
  - type: toggle
    device_id: b907d970f19abd0315596a1ba1209426
    entity_id: switch.shelly1_e8db84d2f87b
    domain: switch
  - wait_template: '00:00:03'
  - type: toggle
    device_id: b907d970f19abd0315596a1ba1209426
    entity_id: switch.shelly1_e8db84d2f87b
    domain: switch
mode: restart

I hope thats now in the correct format. Sorry for inconveniences.

I dont see the Aqara contact sensor entity_id (binary sensor) in the trigger?

That’s your first requirement according to this:

alias: Schiebetor Sicherung (Duplicate)
description: >-
  If the state is open, please check for the last 5 sec and the next 20 sec if
  motions sensor is detecting anything. If triggered, pleas toggle shelly.
trigger:
  - platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_df52bb01_on_off
    to: 'off'
    from: 'on'
condition:
  - type: is_motion
    condition: device
    device_id: 38a7d42dddeea5234579167146c2c2af
    entity_id: binary_sensor.terasse_eingang_on_off
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
action:
  - type: toggle
    device_id: b907d970f19abd0315596a1ba1209426
    entity_id: switch.shelly1_e8db84d2f87b
    domain: switch
  - wait_template: '00:00:03'
  - type: toggle
    device_id: b907d970f19abd0315596a1ba1209426
    entity_id: switch.shelly1_e8db84d2f87b
    domain: switch
mode: restart

Unfortunatelly I tried out too much yesterday, so that I copied the from yaml.
Now you can see the one, I would expect to work.

What you have above is: trigger on the lumi sensor then only perform the actions if the terasse_eingang sensor has been seeing continuous motion for 20 seconds or more.

What you could do instead is trigger on the terasse_eingang sensor detecting movement then use a wait for trigger (for at most 20 seconds) for the lumi sensor to detect movement. If the movement does not occur, do nothing. Like this:

trigger:
  - platform: state
    entity_id: binary_sensor.terasse_eingang_on_off
    to: 'off'
    from: 'on'
action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.lumi_lumi_sensor_magnet_df52bb01_on_off
        to: 'off'
        from: 'on'
    timeout:
      seconds: 20
    continue_on_timeout: false
  - service: switch.toggle
    entity_id: switch.shelly1_e8db84d2f87b
  - delay: 3
  - service: switch.toggle
    entity_id: switch.shelly1_e8db84d2f87b

I guess you need to swap around the first two entities.
Then it should trigger the automation, when the gate is moving (sensor magnet), just like you had it before.

After Wait_for you should be waiting for the motion sensor to detect any motion (Terrasse Eingang)

Hi Tom,

Thanks a lot for your corrections!!!

I copied it 1:1 and it works, but there are still some detailled parameters I need:

a) The second toggle is not working
b) As soon as the shelly gets toggled (second time - done by external control), the gate closes. For my understanding the automation should start from the beginning. Unfortunatelly it does not,…
c) I am not sure, but I think the automatation only works at the moment the sensor detects me.
What I would like to have is, that the automatation is running so long until the sensor is undetecting me.

Looking forward for more help and thank in advance!

I think you might be mistaken about what the toggle service does. It changes the state of the switch once. If the switch is off the toggle service turns it on. If the switch is on the toggle service turns it off. The toggle service does not switch off-on-off.

I have no idea what this means. You are going to have to explain it another way.

The default mode for an automation is single.
With the wait_for_trigger in your automation, it is likely, that the automation is still being active, when you activated the Shelly a second time. If you would like to trigger the automation again, you’d need to change its mode.

My automation is working well now.
Thanks a lot for your support, I think my mistake was the understanding of „toggle“. I thought it would mean change the status of device 2 time, like for example turn on and turn off.