zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[New device support]: Aqara P1 Motion Sensor (MS-S02)

Open backlink-market opened this issue 4 years ago • 75 comments

Link

https://www.aqara.com/en/product/motion-sensor-p1

Database entry

{"id":24,"type":"EndDevice","ieeeAddr":"0x54ef44100043e1a1","nwkAddr":380,"manufId":4447,"manufName":"LUMI","powerSource":"Battery","modelId":"lumi.motion.ac02","epList":[1],"endpoints":{"1":{"profId":260,"epId":1,"devId":263,"inClusterList":[0,1,3,64704],"outClusterList":[3,25,64704],"clusters":{"genBasic":{"attributes":{"appVersion":5,"modelId":"lumi.motion.ac02","manufacturerName":"LUMI","powerSource":3,"zclVersion":3,"hwVersion":1,"dateCode":"Dec 7 2021","swBuildId":"0.0.0_0005"}},"aqaraOpple":{"attributes":{"252":0}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":5,"hwVersion":1,"dateCode":"Dec 7 2021","swBuildId":"0.0.0_0005","zclVersion":3,"interviewCompleted":true,"meta":{},"lastSeen":1648630655174,"defaultSendRequestWhen":"immediate"}

Comments

The new Aqara P1 Motion Sensor (MS-S02) is nearly the same as the Aqara RTCGQ11LM but with two Batteries and a possibilty to change the timeout and constant LUX updates.

backlink-market avatar Mar 30 '22 09:03 backlink-market

@z-x-f @otnow , managed to get this device already? 😄

Koenkk avatar Mar 30 '22 15:03 Koenkk

You can order it here: https://www.gronahus.se/sv/varumarken/aqara/aqara-motion-sensor-p1.html

backlink-market avatar Mar 30 '22 16:03 backlink-market

🙂 Unfortunately, I do not have this sensor, but judging by description, functionally it is a symbiosis of RTCGQ12LM and RTCGQ13LM.

Accordingly, it can be assumed that this sensor uses the logic of its predecessors, i.e. the external converter suggested below might work:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const ota = require('zigbee-herdsman-converters/lib/ota');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
        zigbeeModel: ['lumi.motion.ac02'],
        model: 'RTCGQ14LM',
        vendor: 'Xiaomi',
        whiteLabel: [{vendor: 'Xiaomi', model: 'MS-S02'}],
        description: 'Aqara P1 human body movement and illuminance sensor',
        fromZigbee: [fz.RTCGQ12LM_occupancy_illuminance, fz.aqara_opple, fz.battery],
        toZigbee: [tz.aqara_detection_interval, tz.aqara_motion_sensitivity],
        exposes: [e.occupancy(), e.illuminance().withUnit('lx').withDescription('Measured illuminance in lux'),
            exposes.enum('motion_sensitivity', ea.ALL, ['low', 'medium', 'high']),
            exposes.numeric('detection_interval', ea.ALL).withValueMin(2).withValueMax(65535).withUnit('s')
                .withDescription('Time interval for detecting actions'), e.temperature(), e.battery()],
        meta: {battery: {voltageToPercentage: '3V_2850_3000_log'}},
        configure: async (device, coordinatorEndpoint, logger) => {
            const endpoint = device.getEndpoint(1);
            await endpoint.read('genPowerCfg', ['batteryVoltage']);
            await endpoint.read('aqaraOpple', [0x0102], {manufacturerCode: 0x115f});
            await endpoint.read('aqaraOpple', [0x010c], {manufacturerCode: 0x115f});
        },
        ota: ota.zigbeeOTA,
};

module.exports = definition;

Important: to check the operation of proposed converter, latest ~~stable~~ versions of zigbee2mqtt and firmware of coordinator (at least as indicated here) must be installed.

Otnow avatar Mar 30 '22 16:03 Otnow

I am using the Z-Stack firmware with my SONOFF Zigbee 3.0 USB Dongle via IoBroker with this https://github.com/ioBroker/ioBroker.zigbee adapter. So how can I test your suggestion? Where to add this code?

backlink-market avatar Mar 30 '22 16:03 backlink-market

I am using the Z-Stack firmware with my SONOFF Zigbee 3.0 USB Dongle via IoBroker with this https://github.com/ioBroker/ioBroker.zigbee adapter. So how can I test your suggestion? Where to add this code?

I'm not familiar with IoBroker, so I can't say if it's possible to use an external converter in it.

Maybe someone who knows can tell?

Otnow avatar Mar 30 '22 16:03 Otnow

The iobroker allows the use of external converters, but the feature is not well documented. As such, i need to verify the exact steps which are required and will provide them later today.

A.

p.s. Use of external converters is unwieldy at the moment, and requires editing the paths for the require statements. I am working on changing this to offer use of external converters in an identical fashion to zigbee2mqtt.io. I did provide detailed instructions in the issue on the iobroker.ioBroker.zigbee project.

asgothian avatar Mar 31 '22 05:03 asgothian

🙂 Unfortunately, I do not have this sensor, but judging by description, functionally it is a symbiosis of RTCGQ12LM and RTCGQ13LM.

Accordingly, it can be assumed that this sensor uses the logic of its predecessors, i.e. the external converter suggested below might work:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const ota = require('zigbee-herdsman-converters/lib/ota');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
        zigbeeModel: ['lumi.motion.ac02'],
        model: 'RTCGQ14LM',
        vendor: 'Xiaomi',
        whiteLabel: [{vendor: 'Xiaomi', model: 'MS-S02'}],
        description: 'Aqara P1 human body movement and illuminance sensor',
        fromZigbee: [fz.RTCGQ12LM_occupancy_illuminance, fz.aqara_opple, fz.battery],
        toZigbee: [tz.aqara_detection_interval, tz.aqara_motion_sensitivity],
        exposes: [e.occupancy(), e.illuminance().withUnit('lx').withDescription('Measured illuminance in lux'),
            exposes.enum('motion_sensitivity', ea.ALL, ['low', 'medium', 'high']),
            exposes.numeric('detection_interval', ea.ALL).withValueMin(2).withValueMax(65535).withUnit('s')
                .withDescription('Time interval for detecting actions'), e.temperature(), e.battery()],
        meta: {battery: {voltageToPercentage: '3V_2850_3000_log'}},
        configure: async (device, coordinatorEndpoint, logger) => {
            const endpoint = device.getEndpoint(1);
            await endpoint.read('genPowerCfg', ['batteryVoltage']);
            await endpoint.read('aqaraOpple', [0x0102], {manufacturerCode: 0x115f});
            await endpoint.read('aqaraOpple', [0x010c], {manufacturerCode: 0x115f});
        },
        ota: ota.zigbeeOTA,
};

module.exports = definition;

Important: to check the operation of proposed converter, latest stable versions of zigbee2mqtt and firmware of coordinator (at least as indicated here) must be installed.

Unfortunatly this code is not working. There is a TypeError: TypeError: Cannot read property 'options' of undefined Please see https://github.com/ioBroker/ioBroker.zigbee/issues/1402#issuecomment-1084971902

EDIT: Finally I made the adapter even start without errors by changing this line: toZigbee: [tz.aqara_detection_interval, tz.aqara_motion_sensitivity], to: toZigbee: [tz.aqara_detection_interval, tz.RTCGQ13LM_motion_sensitivity],

and removing the meta. meta: { battery: { voltageToPercentage: '3V_2850_3200' } },

Now I am able to add the sensor but it still throws an error while adding it:

Pairing time left: 27
Error: Error collectOptions for 54ef44100043e1a1. Error: Error: Not batteryVoltageToPercentage type supported: 3V_2850_3000_log
    at batteryVoltageToPercentage (C:\iobroker\MiCasa\node_modules\zigbee-herdsman-converters\lib\utils.js:168:15)
    at Object.convert (C:\iobroker\MiCasa\node_modules\zigbee-herdsman-converters\converters\fromZigbee.js:328:39)
    at C:\iobroker\MiCasa\node_modules\iobroker.zigbee\main.js:462:43
    at StatesController.collectOptions (C:\iobroker\MiCasa\node_modules\iobroker.zigbee\lib\statescontroller.js:179:23)
    at runNextTicks (internal/process/task_queues.js:60:5)
    at processImmediate (internal/timers.js:437:9). undefined
Pairing time left: 28
New device joined '0x54ef44100043e1a1' model RTCGQ14LM
Interview successful: {"friendly_name":"0x54ef44100043e1a1","model":"RTCGQ14LM","vendor":"Xiaomi","description":"Aqara P1 human body movement and illuminance sensor","supported":true}
Pairing time left: 28
Pairing time left: 27
Device '0x54ef44100043e1a1' announced itself
Interview started: 0x54ef44100043e1a1

The occupany, link quality,illuminance_raw and available fields are working the other things are (null) see here: http://prntscr.com/CzEkUQn4otgR

backlink-market avatar Mar 31 '22 19:03 backlink-market

Unfortunatly this code is not working. There is a TypeError: TypeError: Cannot read property 'options' of undefined Please see https://github.com/ioBroker/ioBroker.zigbee/issues/1402#issuecomment-1084971902

I got acquainted with your ioBroker PR and it seems that I understood a little how ioBroker.zigbee module works.

According to ioBroker changelog, ioBroker.zigbee 1.6.16 was released on 2022-02-16 and, accordingly, I can assume that version of zigbee-herdsman-converters used in it corresponds to this date.

My initial version of external converter was designed for development version of zigbee2mqtt (not stable version, as I mistakenly indicated), so it did not work for you, because at the moment, significant changes have been made to zigbee-herdsman-converters.

Try to test this variant adapted, it seems to me, to your version of zigbee-herdsman-converters:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const ota = require('zigbee-herdsman-converters/lib/ota');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
        zigbeeModel: ['lumi.motion.ac02'],
        model: 'RTCGQ13LM',
        vendor: 'Xiaomi',
        whiteLabel: [{vendor: 'Xiaomi', model: 'MS-S02'}],
        description: 'Aqara P1 human body movement and illuminance sensor',
        fromZigbee: [fz.RTCGQ12LM_occupancy_illuminance, fz.aqara_opple, fz.battery],
        toZigbee: [tz.aqara_detection_interval, tz.RTCGQ13LM_motion_sensitivity],
        exposes: [e.occupancy(), e.illuminance().withUnit('lx').withDescription('Measured illuminance in lux'),
            exposes.enum('motion_sensitivity', ea.ALL, ['low', 'medium', 'high']),
            exposes.numeric('detection_interval', ea.ALL).withValueMin(2).withValueMax(65535).withUnit('s')
                .withDescription('Time interval for detecting actions'), e.temperature(), e.battery()],
        meta: {battery: {voltageToPercentage: '3V_2850_3200'}},
        configure: async (device, coordinatorEndpoint, logger) => {
            const endpoint = device.getEndpoint(1);
            await endpoint.read('genPowerCfg', ['batteryVoltage']);
            await endpoint.read('aqaraOpple', [0x0102], {manufacturerCode: 0x115f});
            await endpoint.read('aqaraOpple', [0x010c], {manufacturerCode: 0x115f});
        },
        ota: ota.zigbeeOTA,
};

module.exports = definition;

Changes:

  • tz.aqara_motion_sensitivity replaced by tz.RTCGQ13LM_motion_sensitivity
  • 3V_2850_3000_log replaced by 3V_2850_3200
  • also for testing needs, model RTCGQ14LM is replaced by RTCGQ13LM, so that motion_sensitivity is initialized when pairing

Accordingly, it will be necessary to re-pair the sensor.

Otnow avatar Apr 01 '22 01:04 Otnow

Great, this works well except the motion_sensitivity and detection_interval. Both values are not respected by the sensor when I chage them. Its always the default value. The log shows the following error:

Error 240 on send command to 0x54ef44100043e940. Error: Error: Write 0x54ef44100043e940/1 aqaraOpple({"258":{"value":[30],"type":32}}, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Data request failed with error: 'MAC transaction expired' (240)) at ZStackAdapter.sendZclFrameToEndpointInternal (C:\iobroker\MiCasa\node_modules\zigbee-herdsman\dist\adapter\z-stack\adapter\zStackAdapter.js:331:23) at async Queue.executeNext (C:\iobroker\MiCasa\node_modules\zigbee-herdsman\dist\utils\queue.js:19:32)

backlink-market avatar Apr 01 '22 09:04 backlink-market

Great, this works well except the motion_sensitivity and detection_interval. Both values are not respected by the sensor when I chage them. Its always the default value.

Because since sensor is battery-powered, it is in sleep mode most of the time to save energy and therefore does not respond to commands.

In order for sensor to accept new settings, immediately after changing them in web interface, press button on it to wake it up.

Otnow avatar Apr 01 '22 12:04 Otnow

Because since sensor is battery-powered, it is in sleep mode most of the time to save energy and therefore does not respond to commands.

In order for sensor to accept new settings, immediately after changing them in web interface, press button on it to wake it up.

Ok, did it and the error does not pop up in the log but the sensor still does not respect that value. Occupany is still 60s true before it falls back to false when no motion happens.

backlink-market avatar Apr 01 '22 13:04 backlink-market

Ok, did it and the error does not pop up in the log but the sensor still does not respect that value. Occupany is still 60s true before it falls back to false when no motion happens.

To better understand what's going on, we now need a debug log.

Enable debug messages (it seems to me that this option is visible in this screenshot) and provide a log in which process of pairing sensor and an attempt to change its settings will be visible.

Otnow avatar Apr 01 '22 15:04 Otnow

This is correct. Please note: In order to see the zigbee-herdsman-debug messages, the adapter has to be run in debug mode as well.

A.

asgothian avatar Apr 01 '22 16:04 asgothian

logs are quite big for pasting so I uploaded the log files: Pairing log: pairing_log.txt

changing detection_interval to 10s: changed detection_interval to 10s.txt

note: There might be some unuseful logs stuff before and after but I thought its better to add more than missing something.

backlink-market avatar Apr 01 '22 16:04 backlink-market

Pairing log: https://file.io/EZ3AG2BdNS9e changing detection_interval to 10s: https://file.io/aOixzZmlgaMc

The file.io service reports:

The file you requested has been deleted

There is no need to use a third party service as files can be attached here.

Otnow avatar Apr 01 '22 16:04 Otnow

Pairing log: pairing_log.txt changing detection_interval to 10s: changed detection_interval to 10s.txt

backlink-market avatar Apr 01 '22 18:04 backlink-market

Occupany is still 60s true before it falls back to false when no motion happens.

Pairing log: pairing_log.txt

It's strange that your occupancy is 60 seconds, although during pairing, the sensor reports that detection_interval = 30 seconds:

2022-04-01 18:20:53.350 - debug: zigbee.1 (15728) Received Zigbee message from '0x54ef44100043f0b3', type 'readResponse', cluster 'aqaraOpple', data '{"258":30}' from endpoint 1 with groupID 0
...
2022-04-01 18:20:53.379 - debug: zigbee.1 (15728) Publish {"detection_interval":30} to "54ef44100043f0b3"

changing detection_interval to 10s: changed detection_interval to 10s.txt

I did not find any entry in log about pressing button on sensor after trying to change detection_interval.

Try to write a log with 2-3 attempts to change detection_interval and motion_sensitivity, as well as the start and end of motion detection.

Otnow avatar Apr 01 '22 19:04 Otnow

okay, here we go: changed the interval to 13,14,15 seconds and pushed the button several times. changed detection_interval 13,14,15s.txt

changed the motion_sensitivity several times and pushed the button several times: changed motion sensitivity .txt

backlink-market avatar Apr 02 '22 08:04 backlink-market

changed the interval to 13,14,15 seconds and pushed the button several times. changed detection_interval 13,14,15s.txt

changed the motion_sensitivity several times and pushed the button several times: changed motion sensitivity .txt

These logs show that sensor accepts changed detection_interval and motion_sensitivity settings.

However, I did not see in logs "end of motion detection" event ("occupancy":false), which I asked to record:

as well as the start and end of motion detection.

Try to write a log that will contain following actions:

  • press button on sensor once
  • change motion_sensitivity to high and immediately press button on sensor once (no need to press it several times)
  • change detection_interval to 2 seconds and immediately press button on sensor once (no need to press it several times)
  • wait until sensor stops detecting movement ("occupancy":false)
  • create an active continuous movement in front of sensor for 15-20 seconds
  • do not create any movement in front of sensor until sensor stops detecting movement ("occupancy":false)
  • press button on sensor once

Otnow avatar Apr 02 '22 23:04 Otnow

Ok, this is a exact instructions 👍 Here is the log file: Logfile.txt

backlink-market avatar Apr 03 '22 11:04 backlink-market