Enable/Disable Motion Detection (camera) when Home/Away not working

Hi there,

I bought an Amcrest camera to try it out in Home Assistant, and so far I was able to get it working and to enable/disable the motion detection with a script.

I wanted to automate and enable the motion detection of the camera at midnight at 12am, and/or during the day when everyone is not home.

I tested the state from: home to: not home and vice versa, but it didn’t automate the motion detection to enable / disable.

Can anyone please check which part I got wrong and how can I fix it?

What I basically want to do:

Motion Detection ON:

  • from 12am to 6am
  • everyone is away.

Motion Detection OFF:

  • during the day
  • everyone / someone is home.

Here’s my current code.

Automation:

#Camera - Night Mode
- alias: Camera - Night Mode
  trigger:
  - platform: time
    at: '00:00:00'
  action:
  - service: script.camera_motion_detection_on_script

#Camera Motion Detection - Day Mode
- alias: Camera Motion Detection - Day Mode
  trigger:
  - platform: state
    entity_id: group.family
    from: not home
    to: home
  condition: '{{ now().hour >= 6 and now().hour <= 23 }}'
  action:
  - service: script.camera_motion_detection_off_script

#Camera Motion Detection - Away Mode
- alias: Camera Motion Detection - Away Mode
  trigger:
  - platform: state
    entity_id: group.family
    from: home
    to: not home
  condition: '{{ now().hour >= 6 and now().hour <= 23 }}'
  action:
  - service: script.camera_motion_detection_on_script

Script:

#Camera
#Night Mode
camera_motion_detection_on_script:
  alias: Camera Motion Detection - On Script
  sequence:
  - service: camera.enable_motion_detection
    entity_id: camera.living_room_camera

#Day Mode
camera_motion_detection_off_script:
  alias: Camera Motion Detection - Off Script
  sequence:
  - service: camera.disable_motion_detection
    entity_id: camera.living_room_camera

Thanks.

It’s not_home with an underscore between home and not. You can see the correct state under Developer Tools -> States.