Amcrest Switch Deprecated

I have several Amcrest camera’s working with home assistants. Two of these camera’s use the switch option activated by motion detection from a binary RF motion detection unit. Everything worked until I upgraded to 0.93.1. I have removed all the Amcrest Swithch options in my config.yaml and changed the automatons from switch.turn_on to the Service enable_motion_recording / Service enable_motion_recording/disable_motion_recording. Motion at my motion detector turns on the record motion option in my amcrest camera but the the Service enable_motion_recording / disable_motion_recording does not turn off the cameras record function.
Any help would be appreciated. Thanks

1 Like

First, the switches have only been deprecated, not removed. So you could still use them, at least for a while. I don’t have any immediate plans to remove the deprecated features. But yes, they will get removed at some point, so now’s the time to get the alternate implementation working. :slight_smile:

Next, per the documentation, note the difference between the amcrest.enable_motion_recording/amcrest.disable_motion_recording services and the amcrest.enable_recording/amcrest.disable_recording services. The former enables/disables the camera’s internal feature whereby when it senses motion it will record, whereas the latter immediately enables/disables the camera to record (i.e., immediately starts or stops recording.)

It sounds to me like you’re using the wrong services. I think you should be using amcrest.enable_recording and amcrest.disable_recording. But it’s kind of hard to tell from your description.

It might be helpful if you posted your previous amcrest configuration together with the automation(s) you were using, as well as what you have now.

I have included my Amcrest config from my Configuration.yaml and also the Automation’s for my camera capture function. I am confused, if everything is still available why did everything stop working when I upgrade to 0.93.1 making no changes to my configuration? I am back to 0.91.3 and everything is working. The 2 functions that get turned on in the cameras are motion detection and record with the current automation. These are Amcrest IP4M-1026W and when movement is detected from my motion detectors at my front and back door the cameras are turned on for 3 minutes sending emails with snapshots.
Thanks again for any help.

Can you format the YAML so it can be read correctly?

  - host: 192.168.1.27
    port: 1954
    username: admin
    password: !secret amcrest_password
    name: Amcrest Basement Door
    resolution: high
    stream_source: mjpeg
    sensors:
      - motion_detector
    switches:
      - motion_detection
      - motion_recording
    scan_interval: 5 
	
	  - host: 192.168.1.53
    port: 1955
    username: admin
    password: !secret amcrest_password
    name: Amcrest Front Yard
    resolution: high
    stream_source: mjpeg
    sensors:
      - motion_detector
      - sdcard     
    switches:
      - motion_detection
      - motion_recording 
    scan_interval: 5      
	
	- id: '1546473933619'
  alias: Amcrest Front Yard Camera On
  trigger:
  - entity_id: binary_sensor.front_door_motion
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.motion_detection_amcrest_front_yard
    service: switch.turn_on
  - data:
      entity_id: switch.motion_recording_amcrest_front_yard
    service: switch.turn_on
- id: '1546484088458'
  alias: Amcrest Front Yard Camera Off
  trigger:
  - entity_id: switch.motion_detection_amcrest_front_yard
    for: 0:03:00
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.motion_detection_amcrest_front_yard
    service: switch.turn_off
  - data:
      entity_id: switch.motion_recording_amcrest_front_yard
    service: switch.turn_off
- id: '1546534923585'
  alias: Amcrest Basement Camera On
  trigger:
  - entity_id: binary_sensor.basement_door_motion
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.motion_detection_amcrest_basement_door
    service: switch.turn_on
  - data:
      entity_id: switch.motion_recording_amcrest_basement_door
    service: switch.turn_on
- id: '1546535318547'
  alias: Amcrest Basement Camera Off
  trigger:
  - entity_id: switch.motion_detection_amcrest_basement_door
    for: 0:03:00
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: switch.motion_detection_amcrest_basement_door
    service: switch.turn_off
  - data:
      entity_id: switch.motion_recording_amcrest_basement_door
    service: switch.turn_off

Sorry: Hope this is better kind of new at posting.

Yes, that’s a bit better, thanks, although the indentation is still a bit off. FWIW, the easiest way to post YAML code, log messages, etc. is to type a line with three back-tick characters, then copy and paste the code directly from a text editor, then follow with a line of three more back-tick characters, like this:

```
YAML code
```

Ok, I see what you were doing. When motion detection is seen by a separate sensor, turn on motion detection and motion recording in the camera, which, in theory, sees the same motion and will record, send e-mail, or whatever you have configured it to do in the camera’s settings. Then after three minutes, turn off the camera’s motion detection and motion recording.

Honestly, I can’t see why that still wouldn’t work in 0.93.1. Except…

So looks like I accidentally created a breaking change. All the other entity types (binary_sensor & sensor) have entity_id’s that are DOMAIN.NAME_TYPE (so, e.g., sensor.amcrest_camera_sdcard), but switches were DOMAIN.TYPE_NAME (so, e.g., switch.motion_detection_amcrest_camera.) In cleaning up the code I ended up making switch entity_id’s like the others: DOMAIN.NAME_TYPE.

So the reason your automations aren’t working anymore is because the entity_id’s don’t match. Just change switch.motion_detection_amcrest_front_yard to switch.amcrest_front_yard_motion_detection, and do the same for the other three.

Sorry for the inconvenience. This was not intentional. But since the switches are deprecated at this point, I don’t think I’ll change it back.

Now, having solved that mystery, can you post your updated automations that use the services instead? There should be no reason that shouldn’t work.

As both switches: motion_detection, and motion_recording are deprecated, when will the service ‘enable/disable_motion_detection’ be implemented?

They already are, starting with 0.93.0.

EDIT: To be clear, the services are:

camera.disable_motion_detection
camera.enable_motion_detection

since they were already defined (and registered) by the camera component. (I just added the implementation in the amcrest platform.)

All the other services introduced are in the amcrest domain, since they are unique to the amcrest integration. E.g.:

amcrest.disable_motion_recording
amcrest.enable_motion_recording

etc. Maybe someday some of these services will be considered “standard” enough and be transitioned into the camera domain, but that hasn’t happened.

1 Like

I am still having one problem. My 3 minute timer was dependent on the entity_id: switch.motion_detection_amcrest_basement_door which will no longer be available. Could you recommend what I could use to turn the camera.enable_motion_detection amcrest.enable_motion_recording off after 3 minutes?

Create a three minute timer. Start it when you turn on motion detection and motion recording. You might also want a condition step before that checks that the timer is idle so it doesn’t get restarted if your motion detector goes off and back on before it has finished. (That would make it work the same way as before. On the other hand, maybe it would be better for the timer to restart if that happened. In that case, just don’t use the condition step.) Then trigger the second automation when the timer finishes.

So, e.g., add something like this to the end of the first automation:

  - condition: state
    state: idle
    entity_id: timer.amcrest_basement_door
  - service: timer.start
    entity_id: timer.amcrest_basement_door

Then use this as the trigger for the “off” automation:

  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.amcrest_basement_door

My apologies for hijacking this thread, but I just purchased an AmCrest camera IP4M-1055E, with the intention of replacing my Foscams. I was primarily interested in the Motion Detection binary sensor.
My camera streams fine but the motion sensor (in my case binary_sensor.commonarea_motion_detected) state is always off.
I can get motion detection working fine using the Amcrest app.

What am I missing?

Thank you very much in advance.

Check the attributes of the camera entity. Do you see “motion_detection: true”? If not, use the camera.enable_motion_detection service to enable motion detection.

Well, now I feel stupid. I am using that service for my BLINK cameras and did not think about it.
Works great now!! Thank you very much!

1 Like

Hey @pnbruckner, for my Amcrest camera I noticed that the motion_detection attribute only shows True when motion detection is enabled via camera.enable_motion_detection. The attribute disappears entirely from the list when I call camera.disable_motion_detection. Is this by design or is this a bug? I can write some jinja code for my template sensor to just assume false if the attribute is missing from the list altogether, but it would be cleaner if it just followed the attribute’s value directly, ie:

amcrest_camera_motion_detection_setting:
  value_template: {{ states.camera.amcrest_camera.attributes.motion_detection }}

Yes, and yes.

Yes, I think it is by design by the person who wrote the code. (This is in the camera component level code, not the amcrest integration.) And, yes, I personally think it’s either a bug, or inappropriate behavior.

See the code here.

IMHO, it should be:

        if self.motion_detection_enabled is not None:
            attrs["motion_detection"] = self.motion_detection_enabled

Thanks @pnbruckner. Maybe it will get fixed eventually. Nonetheless, for those interested here is my working code that mimics the behavior of the old deprecated switches. Hope it helps someone else

switch:
  - platform: template
    switches:
      amcrest_motion_detection:
        friendly_name: Amcrest Camera Motion Detection
        value_template: "{{ states.camera.amcrest_camera.attributes.motion_detection is defined and states.camera.amcrest_camera.attributes.motion_detection == True }}"
        icon_template: mdi:run-fast
        turn_on:
          service: camera.enable_motion_detection
          data:
            entity_id: camera.amcrest_camera
        turn_off:
          service: camera.disable_motion_detection
          data:
            entity_id: camera.amcrest_camera
      amcrest_motion_recording:
        friendly_name: Amcrest Camera Motion Recording
        value_template: "{{ states.camera.amcrest_camera.attributes.motion_recording == 'on' }}"
        icon_template: mdi:record-rec
        turn_on:
          service: amcrest.enable_motion_recording
          data:
            entity_id: camera.amcrest_camera
        turn_off:
          service: amcrest.disable_motion_recording
          data:
            entity_id: camera.amcrest_camera  
2 Likes

A slight improvement on the first value_template:

value_template: "{{ is_state_attr('camera.amcrest_camera', 'motion_detection', true) }}"

This will be true if the attribute exists and is true. And it will be false if the attribute exists but is not true, or the attribute doesn’t exist, or even if the entity doesn’t exist.

1 Like

Ah yes, great! Thanks!

Hello,
I’m trying to setup my IP4M-1051 but amcrest.disable_motion_recording/amcrest.enable_motion_recording doesn’t seem to do anything.
When I have this:


camera is recording video on motion regardless of motion_recording value. And if I uncheck Record, it’s not recording anything regardless of motion_recording value.
The sensor works so I guess I can manually trigger amcrest.disable_recording/amcrest.enable_recording in an automation but I’d rather not.