English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Low Power Doorbell

Last Updated on : 2022-02-16 08:56:54download

Check for low power doorbell

TuyaSmartDeviceModel and API methods of the IPC SDK can be called to check whether a low-power doorbell is used.

Example

- (BOOL)isLowPowerDevice;

If an IPC is a low power device, it must be a low power doorbell.

Wake up a low-power device from sleep mode

A low-power doorbell is powered by batteries. This device runs in sleep mode to minimize power consumption if peer-to-peer (P2P) connections are not used within a certain period. P2P connections are unavailable in sleep mode. They can be used only after the device is woken up. The API methods of the class TuyaSmartDevice are called for the wake-up.

Example

- (void)awakeDeviceWithSuccess:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure;

Listen for wake-up of sleep device

When success is returned in the request for wake-up of the sleep doorbell, this response only means that the wake-up command is sent to the device, but does not mean that the device is started. When the device is started, the device reports the data point (DP) TuyaSmartCameraWirelessAwakeDPName with the value YES.

Example

ObjC:

- (void)viewDidLoad {
		[super viewDidLoad];
	self.dpManager = [[TuyaSmartCameraDPManager alloc] initWithDeviceId:self.devId];
		self.device = [TuyaSmartDevice deviceWithDeviceId:self.devId];
		// Adds a listener for the DP.
		[self.dpManager addObserver:self];

	[self start];
}

- (void)start {
	if (self.isConnected) {
				[self.videoContainer addSubview:self.camera.videoView];
				self.camera.videoView.frame = self.videoContainer.bounds;
		[self.camera startPreview];
		}else if (!self.isConnecting) {
		if (self.device.deviceModel.isLowPowerDevice) {
				[self.device awakeDeviceWithSuccess:nil failure:nil];
			}
				[self.camera connect];
		self.isConnecting = YES;
		}
}

Swift:

func viewDidLoad() {
	super.viewDidLoad()
	self.dpManager = TuyaSmartCameraDPManager(deviceId: self.devId)
		self.device = TuyaSmartDevice(deviceId: self.devId)
		// Adds a listener for the DP.
		self.dpManager?.addObserver(self)

	self.start()
}

func start() {
	guard self.isConnected || self.isConnecting else {
			if self.device?.deviceModel.isLowPowerDevice() {
			self.device?.awake(success: nil, failure: nil)
		}
				self.camera.connect()
				self.isConnecting = true
		return
	}
	self.videoContainer.addSubView(self.camera.videoView)
	self.camera.videoView.frame = self.videoContainer.bounds
	self.camera.startPreview()
}

Battery management

A lower-power doorbell can be connected to mains power or powered by batteries. You can call the IPC SDK to query the power mode and the current battery level of the device. A threshold can be set to trigger low battery alerts if needed. After this threshold is reached, the alert will be generated.

Example

ObjC:

- (void)viewDidLoad {
		if ([self.dpManager isSupportDP:TuyaSmartCameraWirelessPowerModeDPName]) {
		TuyaSmartCameraPowerMode powerMode = [[self.dpManager valueForDP:TuyaSmartCameraWirelessPowerModeDPName] tysdk_toString];
		if ([powerMode isEqualToString:TuyaSmartCameraPowerModePlug]) {
						// Connected to mains power.
		}else if ([powerMode isEqualToString:TuyaSmartCameraPowerModeBattery]) {
			// Powered by batteries.
		}

	}

	if ([self.dpManager isSupportDP:TuyaSmartCameraWirelessElectricityDPName]) {
		NSInteger electricity = [[self.dpManager valueForDP:TuyaSmartCameraWirelessElectricityDPName] tysdk_toInt];
		NSLog(@"Current battery level: %@%%", @(electricity));
	}

	if ([self.dpManager isSupportDP:TuyaSmartCameraWirelessLowpowerDPName]) {
		// If the device's battery level is lower than the threshold, an alert is triggered.
		[self.dpManager setValue:@(20) forDP:TuyaSmartCameraWirelessLowpowerDPName success:^(id result) {

		} failure:^(NSError *error) {
			// A network error.
		}];
	}

	if ([self.dpManager isSupportDP:TuyaSmartCameraWirelessBatteryLockDPName]) {
		// Release the battery lock to remove the battery.
		[self.dpManager setValue:@(NO) forDP:TuyaSmartCameraWirelessBatteryLockDPName success:^(id result) {

		} failure:^(NSError *error) {
			// A network error.
		}];
	}
}

Swift:

override func viewDidLoad() {
	super.viewDidLoad()
	if self.dpManager.isSupportDP(.wirelessPowerModeDPName) {
		let powerMode = self.dpManager.value(forDP: .wirelessPowerModeDPName) as! String
		switch TuyaSmartCameraPowerMode(rawValue: powerMode) {
		case .plug: break
			// Connected to mains power.
		case .battery: break
			// Powered by batteries.
		default: break
		}
	}

	if self.dpManager.isSupportDP(.wirelessElectricityDPName) {
		let electricity = self.dpManager.value(forDP: .wirelessElectricityDPName) as! Int
		print("Current battery level: ", electricity)
	}

	if self.dpManager.isSupportDP(.wirelessLowpowerDPName) {
		// If the device's battery level is lower than the threshold, an alert is triggered.
		self.dpManager.setValue(20, forDP: .wirelessLowpowerDPName, success: { _ in

		}) { _ in
			// A network error.
		}
	}

	if self.dpManager.isSupportDP(.wirelessBatteryLockDPName) {
		// Release the battery lock to remove the battery.
		self.dpManager.setValue(false, forDP: .wirelessBatteryLockDPName, success: { _ in

		}) { _ in
			// A network error.
		}
	}
}

Doorbell audio resource file

To implement the features of the low-power doorbell, you must download the default resource file resources.zip, decompress it, and then add the resources to your project. You can also add a custom audio file with the default file name.