Amcrest additional binary sensors

Currently Amcrest supports multiple services but not corresponding sensors to see if they worked or not.

Please include in binary_sensor:

BINARY_SENSOR_MOTION_DETECTION = "motion_detection"
BINARY_SENSOR_RECORD_ON_MOTION = "record_on_motion"
BINARY_SENSOR_AUDIO = "audio"
.
.
.
BINARY_SENSOR_MOTION_DETECTION: ("Motion Detection", None, "mdi:motion-sensor"),
BINARY_SENSOR_RECORD_ON_MOTION: ("Record on Motion", None, "mdi:record-rec"),
BINARY_SENSOR_AUDIO: ("Audio", DEVICE_CLASS_SOUND, None),
.
.
.

    def __extract_status(self, dahua_attribute):
        ret = self._api.motion_detection
        full_dahua_attribute = ".{}=".format(dahua_attribute)
        status = [s for s in ret.split() if full_dahua_attribute in s][0]\
            .split('=')[-1]
        if status.lower() == 'true':
            return True
        else:
            return False

    def update(self):
        """Update entity."""
        if not self.available:
            return
        _LOGGER.debug("Updating %s binary sensor", self._name)

        try:
            if self._sensor_type == BINARY_SENSOR_MOTION_DETECTED:
                self._state = self._api.is_motion_detected

            elif self._sensor_type == BINARY_SENSOR_ONLINE:
                self._state = self._api.available

            elif self._sensor_type == BINARY_SENSOR_MOTION_DETECTION:
                self._state = self.__extract_status('Enable')

            elif self._sensor_type == BINARY_SENSOR_RECORD_ON_MOTION:
                self._state = self.__extract_status('RecordEnable')
            
            elif self._sensor_type == BINARY_SENSOR_AUDIO:
                self._state = self._api.audio_enabled

These values are already available via the camera entity’s attributes:

  • motion_detection – corresponds to self._api.is_motion_detector_on (i.e., your 'Enable')
  • motion_recording – corresponds to self._api.is_record_on_motion_detection (i.e., your 'RecordEnable')
  • audio – corresponds to self._api.audio_enabled

If you’d like them as binary sensors you can do that by extracting the camera attributes via template binary sensors. The only one that would be a little tricky is motion_detection, because it’s not 'on' or 'off' like the others but rather is present with a value of true when on, and not present when off. (I tried to change that but I wasn’t allowed. That behavior is controlled by the camera component level code, not the amcrest integration code.)

Thanks, I missed attributes reported. In attributes I do not see motion detection though (different version?). In automation I disable streaming via camera.turn_off and disable motion detection, so I preferred to have binary sensors to monitor the status (in case something fails).
And I thought of having binary sensors from package (not just for me) to reflect services actions.
Anyway thanks for the reply

I don’t agree with this behavior, but like I said, I tried to change it but got shot down. This template should work anyway:

{{ is_state_attr('camera.XXX', 'motion_detection', true) }}

For the others, like motion_recording, it would be like this:

{{ is_state_attr('camera.XXX', 'motion_recording', 'on') }}

Yes, like I said, that is easily done by creating Template Binary Sensors.

Thanks a lot. I created templates before i read the reply, but templates match and work just fine.
Thanks for your time and have a nice day

1 Like