Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge πŸŒ‰, get rid of your proprietary Zigbee bridges πŸ”¨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.96k stars 1.67k forks source link

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

Closed backlink-market closed 2 years ago

backlink-market commented 2 years ago

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.

Koenkk commented 2 years ago

@z-x-f @otnow , managed to get this device already? πŸ˜„

backlink-market commented 2 years ago

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

Otnow commented 2 years ago

πŸ™‚ 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.

backlink-market commented 2 years ago

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?

Otnow commented 2 years ago

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?

asgothian commented 2 years ago

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.

backlink-market commented 2 years ago

πŸ™‚ 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

Otnow commented 2 years ago

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:

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

backlink-market commented 2 years ago

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)
Otnow commented 2 years ago

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.

backlink-market commented 2 years ago

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.

Otnow commented 2 years ago

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.

asgothian commented 2 years ago

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.

backlink-market commented 2 years ago

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.

Otnow commented 2 years ago

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.

backlink-market commented 2 years ago

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

Otnow commented 2 years ago

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.

backlink-market commented 2 years ago

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

Otnow commented 2 years ago

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:

backlink-market commented 2 years ago

Ok, this is a exact instructions πŸ‘ Here is the log file: Logfile.txt

Otnow commented 2 years ago

Here is the log file: Logfile.txt

Very good. Judging by log, sensor accepts settings and follows them, but for some reason converter timeout does not correspond to detection_interval and is equal to default value (60 seconds), although there is a record of state change:

2022-04-03 13:40:23.153 - debug: zigbee.1 (8604) convert result {"state":{"detection_interval":2}}

This is strange and I still can not understand reason for discrepancy.

I would like to take a look at values of states of this sensor. Is it possible in ioBroker to see current states of sensor like in zigbee2mqtt web-interface?:

Zigbee2MQTT_states

I also noticed in log that you have a lumi.motion.agl04 (RTCGQ13LM) sensor on network. The timeout algorithm in its converter is same as in what we are currently using for lumi.motion.ac02 (MS-S02). Hence the question - does lumi.motion.agl04 work correctly for you, i.e. does timeout match value of detection_interval?

backlink-market commented 2 years ago

Do you mean this: Screenshot_2

When I change the detection_interval in the RTCGQ13LM settings it shows the timeout error: Send command to 0x54ef441000398e05 failed with no error code (Timeout - 19045 - 1 - 241 - 64704 - 4 after 10000ms)

When I try to wake up the sensor via button on the back it does not work. So the value is not set.

Otnow commented 2 years ago

Do you mean this:

This is a little different, it seems to me that this is an analogue of Exposes in the zigbee2mqtt web-interface.

In zigbee2mqtt, device states can be found in state.json file in data subdirectory. Maybe in ioBroker there is something similar?

When I change the detection_interval in the RTCGQ13LM settings it shows the timeout error: Send command to 0x54ef441000398e05 failed with no error code (Timeout - 19045 - 1 - 241 - 64704 - 4 after 10000ms)

When I try to wake up the sensor via button on the back it does not work. So the value is not set.

Also strange. Unable to set detection_interval on both lumi.motion.agl04 sensors?

@asgothian, can you tell us where in ioBroker we can see device states and can there be a problem with writing or reading states (in our case it is detection_interval)?

asgothian commented 2 years ago

The way it works in iobroker:

If a device offers a read function but no value is read, a message is left in the log. The same is true if a device does not actually acknowledge a "set" command.

A.

Otnow commented 2 years ago

@asgothian, ok, thanks. How can we find out the exact version of zigbee-herdsman-converters that is used in @backlink-market's ioBroker?

backlink-market commented 2 years ago

I am using Zigbee Adapter v1.6.16. Maybe @asgothian can help

backlink-market commented 2 years ago

@Otnow I just checked the folder node_modules\zigbee-herdsman-converters and found the file package.json: package.json.txt

The file contains this: "raw": "zigbee-herdsman-converters@14.0.422",

So I think the version you are looking for is 14.0.422 , right?

Otnow commented 2 years ago

So I think the version you are looking for is 14.0.422 , right?

Yes, that's right.

I installed ioBroker (v5.3.4) + ioBroker.zigbee (v1.6.16) on Windows and found cause of problem.

The following code is used to set timeout value in fz.RTCGQ12LM_occupancy_illuminance:

const timeout = meta && meta.state && meta.state.hasOwnProperty('detection_interval') ? meta.state.detection_interval : 60;

In zigbee2mqtt, this code works correctly, but in ioBroker.zigbee it does not work correctly, because meta.state object does not exist in it and the condition check always returns false, so default value (60 sec) is set regardless of value detection_interval.

This issue affects motion sensors RTCGQ12LM, RTCGQ13LM and current RTCGQ14LM and solving it requires adding support for meta.state object to ioBroker.zigbee.

As a result, judging by logs, converter works correctly, so I created a PR to add support for RTCGQ14LM to zigbee2mqtt.

backlink-market commented 2 years ago

Thank you very much. So, this is a job for @asgothian to update the ioBroker.zigbee, right?

Otnow commented 2 years ago

Thank you very much.

πŸ‘

So, this is a job for @asgothian to update the ioBroker.zigbee, right?

Yes, requires adding support for meta.state object to ioBroker.zigbee.

ScottG489 commented 2 years ago

For anyone coming across this thread, to get this device recognized, the first config offered in https://github.com/Koenkk/zigbee2mqtt/issues/11990#issuecomment-1083365730 is what worked for me, not the amended one mentioned in https://github.com/Koenkk/zigbee2mqtt/issues/11990#issuecomment-1085301841. The amended one actually caused the error mentioned (Cannot read property 'options' of undefined) it was purportedly supposed to fix.

I was able to get the sensitivity and timeout working as well by pressing the button around the time I was sending the update. However, I'm not exactly sure how to "submit" these updates via the UI since there are just text fields and no "submit" button, so I don't know the exact ordering or timing to get the setting to pick up. I'm also not sure if I should be using the "Exposes" or "Settings (specific)" tab in the UI since both seem to let you enter the value. After a little testing, pressing the button and then updating the value via Home Assistant works best for me (though doing this in the zigbee2mqtt interface probably has the same effect).

I have also seen the following error show up from time to time which I assume is a failed update:

Publish 'set' 'detection_interval' to '0x<redacted>' failed: 'Error: Write 0x<redacted>/1 aqaraOpple({"258":{"value":[5],"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))'

Also a question for the maintainers: I saw the PR mentioned above (https://github.com/Koenkk/zigbee-herdsman-converters/pull/4099) was merged. I assume once this makes it's way into the stable version, the HA add-on updates to use that, then I can remove this external converter? Any estimate on about when that would be?

I'm new to this since I just migrated to zigbee2mqtt from ZHA yesterday :) Really love it so far! My Aqara vibration sensor has a lot more info coming into HA too!

Otnow commented 2 years ago

The amended one actually caused the error mentioned (Cannot read property 'options' of undefined) it was purportedly supposed to fix.

You didn't read the discussion carefully.

The modified version of converter was not intended for the current version of zigbee2mqtt, but for a specific version of third-party software (ioBroker) built on its basis, so it is logical that it did not work for you.

I assume once this makes it's way into the stable version, the HA add-on updates to use that, then I can remove this external converter? Any estimate on about when that would be?

Yes, is now available in the dev branch zigbee2mqtt, and will appear in the master branch (stable) at the beginning of next month.

ScottG489 commented 2 years ago

You're right that I didn't read carefully :) Regardless, thought I'd call out which one worked for me for the next person coming to this thread to sift through easier.

Thanks again for helping with this. It's been working great!

digiblur commented 2 years ago

The amended one actually caused the error mentioned (Cannot read property 'options' of undefined) it was purportedly supposed to fix.

You didn't read the discussion carefully.

The modified version of converter was not intended for the current version of zigbee2mqtt, but for a specific version of third-party software (ioBroker) built on its basis, so it is logical that it did not work for you.

I assume once this makes it's way into the stable version, the HA add-on updates to use that, then I can remove this external converter? Any estimate on about when that would be?

Yes, is now available in the dev branch zigbee2mqtt, and will appear in the master branch (stable) at the beginning of next month.

Thanks for your work on this sensor. Working great! Only thing I noticed is the interval slider in Z2M allows the scale to be set further than allowed so it throws an error. Easy fix to just punch in the number you want.

spn91 commented 2 years ago

Should this device already work with the latest version of the Home Assistant Edge Addon? I added it today to Z2M, but it didn't report motion or illuminance. This was just a short test (I am evaluating switching from deconz), so I have no logs at the moment. Just wanted to ask if it should work with the Addon.

Otnow commented 2 years ago

Should this device already work with the latest version of the Home Assistant Edge Addon? I added it today to Z2M, but it didn't report motion or illuminance.

Yes, it should work.

Verify that the coordinator firmware version you are using meets the following requirements.

spn91 commented 2 years ago

That's exactly the firmware which is installed on my Conbee II

Otnow commented 2 years ago

That's exactly the firmware which is installed on my Conbee II

Try to re-pair the sensor and if it doesn’t help, then turn on the debug mode (log_level: debug) and write a log in which the pairing process will be visible, then pressing the button once and the moment of movement in front of the sensor.

spn91 commented 2 years ago

Very strange, I have re-paired it multiple times yesterday. Now I have switched to the stable addon and added it via external converter and it is working now. I don't know what was wrong with it yesterday. Thanks for the help and the great software πŸ‘

Otnow commented 2 years ago

Judging by the screenshot of the sensor settings from the Aqara Home app, there is also the trigger indicator option, the support of which has not yet been implemented, so I made an appropriate note in the description.

Motion-Sensor P1

Otnow commented 2 years ago

During the discussion, it was decided to add information about feature support to the documentation instead of a sensor description.

TheJulianJES commented 2 years ago

Sorry for this just being an image for now -- I've read out the first 400 attributes on the Aqara Opple cluster (0xfcc0) on endpoint 1: image

So far, only the attributes 258/0x0102 (detection interval) and 268/0x010c (motion sensitivity) are known. I'll try to play around with writing these attributes and will report back.

TheJulianJES commented 2 years ago

After some trial and error, it seems to be attribute 338/0x0152.

0: trigger indicator LED disabled 1: trigger indicator LED enabled

Otnow commented 2 years ago

@TheJulianJES, thanks a lot πŸ‘

@ScottG489, @digiblur, @spn91 and other owners of this sensor, please test the trigger indicator option using the following external converter:

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 herdsman = require('zigbee-herdsman');
const manufacturerOptions = {
    xiaomi: {manufacturerCode: herdsman.Zcl.ManufacturerCode.LUMI_UNITED_TECH, disableDefaultResponse: true},
};

const fzLocal = {
    RTCGQ14LM_trigger_indicator: {
        cluster: 'aqaraOpple',
        type: ['attributeReport', 'readResponse'],
        convert: (model, msg, publish, options, meta) => {
            if (msg.data.hasOwnProperty('338')) {
                return {trigger_indicator: msg.data['338'] === 1};
            }
        },
    }
}

const tzLocal = {
    RTCGQ14LM_trigger_indicator: {
        key: ['trigger_indicator'],
        convertSet: async (entity, key, value, meta) => {
            const lookup = {true: 1, false: 0};
            await entity.write('aqaraOpple', {0x0152: {value: lookup[value], type: 0x20}}, manufacturerOptions.xiaomi);
            return {state: {trigger_indicator: value}};
        },
        convertGet: async (entity, key, meta) => {
            await entity.read('aqaraOpple', [0x0152], manufacturerOptions.xiaomi);
        },
    }
}

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.aqara_occupancy_illuminance, fz.aqara_opple, fz.battery, fzLocal.RTCGQ14LM_trigger_indicator],
    toZigbee: [tz.aqara_detection_interval, tz.aqara_motion_sensitivity, tzLocal.RTCGQ14LM_trigger_indicator],
    exposes: [e.occupancy(), e.illuminance_lux().withProperty('illuminance'),
        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'),
        exposes.binary('trigger_indicator', ea.ALL, true, false).withDescription('When this option is enabled then ' +
            'blue LED will blink once when motion is detected'), 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});
        await endpoint.read('aqaraOpple', [0x0152], {manufacturerCode: 0x115f});
    },
    ota: ota.zigbeeOTA,
};

module.exports = definition;

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

In case of successful testing, please write a debug log with the following actions:

bzeiss commented 2 years ago

Sorry for being a newbie. I wanted to try this external converter as I want to mount the P1 in my bedroom and the led would be annoying. I have tried to add this external converter to the zigbee2mqtt 1.25.1-1 config file (installed as Home Assistant addon) as well as through the zigbee2mqtt setting UI and have placed the aqara_p1.js file in the /config/zigbee2mqtt (=data directory). It seems that on pairing the already existing internal converter is used. I have altered the description in the .js file a little so that I could see the difference. Is there any way I can control which converter is used?

Otnow commented 2 years ago

@bzeiss, as far as I understand, you tried to use an external converter according to the instructions. Right?

After changing the settings, you need to restart zigbee2mqtt and, as you correctly noted, you can understand that it is the external converter that is working according to the modified description.

bzeiss commented 2 years ago

@Otnow Thanks for answering. Yes, I somehow made it work. Not sure why it didn't work before, it was probably related to a missing restart as you suggested. The trigger indicator setting seems to work for me. It's not blinking any more. Thanks!

bzeiss commented 2 years ago

@Otnow I have followed your instructions for the debug log. I hope this helps. The sensor address is 0x54ef44100049756c.

log.txt

One thing that is a little irritating for me is the motion sensor sensitivity. When I put it on high, I still need to be more or less directly in front of the sensor in order to activate it. I have the old aqara motion sensors and they activate when I'm pretty far away.

digiblur commented 2 years ago

@bzeiss same kind of oddness I found at times https://youtu.be/qWVbsZCj6CY

Otnow commented 2 years ago

@bzeiss, great, and thank you for the log, this is what I needed πŸ‘

Created a PR to add support for the trigger indicator option to the zigbee2mqtt repository.

One thing that is a little irritating for me is the motion sensor sensitivity. When I put it on high, I still need to be more or less directly in front of the sensor in order to activate it. I have the old aqara motion sensors and they activate when I'm pretty far away.

The sensitivity setting was added by analogy with the RTCGQ13LM, so it is likely that it still works a little differently in the RTCGQ14LM.

In the RTCGQ14LM there may be a reverse sequence of sensitivity settings, in other words, try to set low sensitivity instead of high and test the sensor again.