Turn Plug on with camera motion sensor

Hello, this is my first time writing in this community, thanks for sharing all your knowledge, it has helped me to know more about the Home Assistant application.

I have an amcrest camera in the basement, and a group of lights connected to a Tp Link outlet.

I have both devices in Home Assistant, as I have little knowledge on this subject, I need your help.

My idea is that when the camera detects the movement, the tp link outlet will turn on automatically for a period of 5 minutes, after when the camera detects no movement, the power outlet will be turned off again.

Additionally send me an email when the movement is detected.

This is my current configuration in Home Assistant:

configuration.yaml
      - name: julio_camera
        platform: smtp
        server: smtpgmail
        port: 587
        timeout: 15
        sender: test
        encryption: starttls
        username: test
        password: supersecret
        recipient:
          - formetest
        sender_name: My Home Assistant

    amcrest:
      - host: camera
        username: admin
        password: supersecret
        sensors:
          - motion_detector
          - sdcard
          - ptz_preset
        switches:
          - motion_detection
          - motion_recording
        resolution: low
        stream_source: mjpeg

    camera:
      - platform: amcrest
      
    switch:
      - platform: tplink
        host: plug
        name: "Basement Plug"

Thanks for your help.

Hi,
You can easily do this with 2 automations.
The first automation will be triggered if the state of your binary_sensor.motion_sensor_name changes from “off” to “on” and execute at least one action, calling the service “switch.turn_on” with the entity_id of your TP-Link Outlet.
Here’s how it would look like in the Interface:


You can add more actions like call service notify.notifier_name, Delay 5 minutes (00:05:00) then switch.turn_off.

The second Automation would be triggered when the state of your motion sensor changes from “on” to “off” and calls the service switch.turn_off.

Hi, thanks for your answer, I try right now, but the true is I can’t found the same interface you show me in the image for make the code, can you tell me where it is please?

I found it, I try right now, if I have trouble I tell you. Thanks

Thanks for your instructions I could do the automation, thank you very much.

Glad to hear that it’s working! Enjoy the first of many automations! We all started with one…