Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.2k stars 1.68k forks source link

[New device support]: Aqara wireless relay controller T2 #18856

Open manbading opened 1 year ago

manbading commented 1 year ago

Link

https://www.aqara.com/controller_overview

Database entry

{"id":13,"type":"Router","ieeeAddr":"0x54ef44100092e5e2","nwkAddr":14162,"manufId":4447,"manufName":"Aqara","powerSource":"DC Source","modelId":"lumi.switch.acn047","epList":[1,2,21],"endpoints":{"1":{"profId":260,"epId":1,"devId":0,"inClusterList":[2820,1794,5,4,3,18,0,6,64704],"outClusterList":[25,10],"clusters":{"genBasic":{"attributes":{"modelId":"lumi.switch.acn047","appVersion":27}},"genOnOff":{"attributes":{"245":117440575,"onOff":0}},"aqaraOpple":{"attributes":{"10":1,"223":{"type":"Buffer","data":[22,33,0,0,23,33,0,0,12,33,0,0,24,33,0,0]},"229":{"type":"Buffer","data":[6,0,6,0,0,36,73,68,93,37,8,252,100,37,68,228,103,37,8,175,112,5,188,150,152,37,93]},"235":200,"247":{"type":"Buffer","data":[3,40,37,5,33,18,0,9,33,0,4,10,33,0,0,12,32,10,13,35,27,0,0,0,17,35,1,0,0,0,100,16,0,101,16,0,149,57,0,0,0,0,150,57,205,132,12,69,152,57,0,0,0,0,151,57,0,0,0,0,154,32,0]},"512":1,"515":0,"649":0,"720":0,"1303":1}}},"binds":[{"cluster":6,"type":"endpoint","deviceIeeeAddress":"0x00124b0026b747c7","endpointID":1}],"configuredReportings":[{"cluster":6,"attrId":0,"minRepIntval":0,"maxRepIntval":3600,"repChange":0}],"meta":{}},"2":{"profId":260,"epId":2,"devId":0,"inClusterList":[5,4,3,18,6,64704],"outClusterList":[],"clusters":{"genOnOff":{"attributes":{"245":53957120,"onOff":1}},"aqaraOpple":{"attributes":{"512":1}}},"binds":[],"configuredReportings":[],"meta":{}},"21":{"profId":260,"epId":21,"devId":0,"inClusterList":[12],"outClusterList":[],"clusters":{"genAnalogInput":{"attributes":{"presentValue":0}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":27,"stackVersion":27,"hwVersion":1,"dateCode":"20230606","zclVersion":3,"interviewCompleted":true,"meta":{"configured":1466202208},"lastSeen":1693799779280,"defaultSendRequestWhen":"immediate"}

Comments

I tried to control the lamp with external_converter, but only can turn it ON and OFF.

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 reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    zigbeeModel: ['lumi.switch.acn047'],
    model: 'LLKZMK12LM',
    vendor: 'Xiaomi',
    description: 'Aqara wireless relay controller T2',
    fromZigbee: [fz.xiaomi_basic, fz.xiaomi_power, fz.ignore_multistate_report, fz.on_off, fz.temperature],
    toZigbee: [tz.on_off, tz.LLKZMK11LM_interlock, tz.xiaomi_power, tz.xiaomi_switch_power_outage_memory],
    exposes: [e.switch()],
    // The configure method below is needed to make the device reports on/off state changes
    // when the device is controlled manually through the button on it.
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
        await reporting.onOff(endpoint);
    },
};

module.exports = definition;

Supported color modes

No response

Color temperature range

No response

kei81131 commented 1 year ago

Hi, I made a convertor, that can control L1/ L2 separately and show energy status However, fail to get switch_type/ flip_indicator_light/ power_outage_memory (so I commented those codes)

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 reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    zigbeeModel: ['lumi.switch.acn047'], 
    model: 'LLKZMK12LM', 
    vendor: 'Xiaomi', 
    description: 'Aqara Dual Relay Module T2', 
    fromZigbee: [
        fz.on_off,
        fz.aqara_opple,
        fz.xiaomi_power
    ],
    toZigbee: [
        tz.on_off
        // tz.xiaomi_switch_operation_mode_opple,
        // tz.xiaomi_flip_indicator_light,
        // tz.xiaomi_switch_power_outage_memory
    ], 
    meta: {multiEndpoint: true},
    endpoint: (device) => {
        return { 'l1': 1, 'l2': 2 };
    },
    exposes: [
        e.switch().withEndpoint('l1'),
        e.switch().withEndpoint('l2'),
        e.power(),
        e.current(),
        e.energy(),
        e.voltage(),
        e.device_temperature()
        // e.switch_type(),
        // e.flip_indicator_light(),
        // e.power_outage_memory()
    ],
};

module.exports = definition;
Koenkk commented 1 year ago
kei81131 commented 1 year ago

Thanks for your advice. I've changed convertor, sadly it shows error

Those features are supported in Aqara app. BTW, my main purpose is to get energy status, other features are not necessary to me

Again, thank you Koenkk and zigbee2mqtt is greatful

LLKZMK12LM_power_outage_memory Error 2023-09-12 09:51:57Publish 'set' 'power_outage_memory' to 'Toilet double socket' failed: 'ReferenceError: manufacturerOptions is not defined'

Koenkk commented 1 year ago

Made a mistake, updated https://gist.github.com/Koenkk/4d8b2b11998465c7e8228d18e4a9e8e3

kei81131 commented 1 year ago

Made a mistake, updated https://gist.github.com/Koenkk/4d8b2b11998465c7e8228d18e4a9e8e3

Thanks Koenkk After changing converter, power_outage_momory returns another error Here's the error shown, thank you

LLKZMK12LM_power_outage_memory

Error 2023-09-14 09:35:36Publish 'set' 'power_outage_memory' to 'Toilet double socket' failed: 'Error: Write 0x54ef44100092f9b2/1 genBasic({"65520":{"value":[170,128,5,209,71,7,1,16,1],"type":65}}, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Status 'UNSUPPORTED_ATTRIBUTE')'

Koenkk commented 1 year ago

Seems this device works different than e.g. the LLKZMK11LM, to add support for these function sniffing with the Xiaomi gateway when setting these options is needed.

https://www.zigbee2mqtt.io/advanced/zigbee/04_sniff_zigbee_traffic.html

kei81131 commented 1 year ago

Seems this device works different than e.g. the LLKZMK11LM, to add support for these function sniffing with the Xiaomi gateway when setting these options is needed.

https://www.zigbee2mqtt.io/advanced/zigbee/04_sniff_zigbee_traffic.html

Thanks But it seems too advanced for me study, study, study...…

Koenkk commented 1 year ago

No problem, I've added initial support for this device without the power outage memory.

Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/advanced/more/switch-to-dev-branch.html)

timdemand commented 1 year ago

Hi, thanks for making the initial support available, is it possible to add device specific options for the interlock mode? This is very important for roller shutter operation, as there must only be one phase active at any moment. I dont have an Aqara Hub unfortunatly so I can't sniff traffic for that option.

AitNev commented 1 year ago

Sadly I neither have an Aqara Hub and thankfully it works on Z2M

Even if the interlock feature is not found. Is is possible to do the interlock functionality within Z2M? All we need is to read the states of the switch and safely only turn one switch at a time finally publish an interface that only allows to push up or push down the roller. Right now I don't know how to do it but it might do the trick for the time being.

Another way is to address this by hardware

HardGay commented 1 year ago

I have add this device to my network, but i think the energy meter is not kWH but is Wh, can you correct the définition ?

timdemand commented 1 year ago

Sadly I neither have an Aqara Hub and thankfully it works on Z2M

Even if the interlock feature is not found. Is is possible to do the interlock functionality within Z2M? All we need is to read the states of the switch and safely only turn one switch at a time finally publish an interface that only allows to push up or push down the roller. Right now I don't know how to do it but it might do the trick for the time being.

Another way is to address this by hardware

I think hardware support should be possible, Aqara supports this via their app but it isn't an app feature but more a device option. It would be alot better than software, as you still need to make sure that your hardware buttons are also interlocked...

I have add this device to my network, but i think the energy meter is not kWH but is Wh, can you correct the définition ?

I noticed that too

HardGay commented 1 year ago

Hi, add more the energy correct to kWH, can you check the data source of energy because in the history chart, the curve seems linear .. I use this device to follow my solar product and the curve must be more chaotic 😁

HardGay commented 1 year ago

IMG_1834

HardGay commented 1 year ago

À good historic chart 👍 IMG_1835

nicocha75 commented 1 year ago

Hello, some function are note present in module configuration This module can be configured with pulse commande or interlock to be use with shutter. This parameter can be seen with xiomi hub (that i don't have).

jb1228 commented 1 year ago

I just bought this device since I saw it was supported.

I was able to hook it up to control my garage door (although I have to turn the switch on then off again). However, the sensors (S1/S2) don't seem to be available. I use them for my open/closed contact sensors.

Is this something that can be added or is there a config I can use to expose them?

Thanks. 😊

xirius commented 1 year ago

Has anyone found out how to set Interlock mode ?

DAVIZINH0 commented 12 months ago

I have add this device to my network, but i think the energy meter is not kWH but is Wh, can you correct the définition ?

i think the same. the energy meter its imposible to measure in kwh. a simply lamp have more consumption than a lot of devices in my home, jejeje

can i change this in zigbee2mqtt or need a new version?

latel commented 11 months ago

Has anyone found out how to set Interlock mode ?

yeah, I want this interlock mode, too

latel commented 11 months ago

hey guys, I saw the interlock is implemented already in https://github.com/Koenkk/zigbee-herdsman-converters/pull/6554, but works not alright.

@xirius

ShaunTosler commented 11 months ago

I have add this device to my network, but i think the energy meter is not kWH but is Wh, can you correct the définition ?

i think the same. the energy meter its imposible to measure in kwh. a simply lamp have more consumption than a lot of devices in my home, jejeje

can i change this in zigbee2mqtt or need a new version?

I also concur that this reading is in kW and is most defiantly not kWh - everything else is working as expected apart from it thinks that my Gas boiler has used 97kWh of electricity in an hour. This is compliantly imposable. That's nearly 6 times the energy suppliers daily meter reading of the whole house. When you do the math's of an average of 0.4A (at 240v) over the same time is 95Wh confirming this. To pull 95kWh in the same time period, I would have to be drawing 395A. I dont think my neighbors or my DNO would like me if that was the case on my domestic supply 😆

Is it possible to divide this by 1000 in the config to make it 95 wH?

Matssa56 commented 10 months ago

Hi everyone, Not sure if I need to open another bug ticket but I repaired every zigbee device I have at home and I keep getting an error concerning this device. Here is the log:

Zigbee2MQTT:error 2024-01-07 21:25:33: Exception while calling fromZigbee converter: Expected one of: 1, 2, 3, got: 'undefined'}
Zigbee2MQTT:error 2024-01-07 21:25:33: Failed to configure 'Relais PaC', attempt 3 (Error: Read 0x54ef441000990ea9/2 aqaraOpple([10], {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Status 'UNSUPPORTED_ATTRIBUTE')
    at Endpoint.checkStatus (/app/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:321:28)
    at Endpoint.read (/app/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:463:22)
    at setupAttributes (/app/node_modules/zigbee-herdsman-converters/src/lib/modernExtend.ts:62:9)
    at configure (/app/node_modules/zigbee-herdsman-converters/src/lib/modernExtend.ts:72:9)
    at Object.configure (/app/node_modules/zigbee-herdsman-converters/src/index.ts:140:25)
    at Configure.configure (/app/lib/extension/configure.ts:120:13)
    at EventEmitter.wrappedCallback (/app/lib/eventBus.ts:167:17))

The device itself appears to work fine when changing L1 or L2. I'm currently configured as below:

image

Is it maybe linked to the new Zigbee2Mqtt update where it tries to automatically get functions for unsupported devices?

lsc597 commented 10 months ago

I just bought this device since I saw it was supported.

I was able to hook it up to control my garage door (although I have to turn the switch on then off again). However, the sensors (S1/S2) don't seem to be available. I use them for my open/closed contact sensors.

Is this something that can be added or is there a config I can use to expose them?

Thanks. 😊

Hello, this is also a problem I am facing. Want to use S1 as a manual button for garage opening/closing and S2 for monitoring the state of the door with a magnetic contact sensor. For this ideally I should be able to configure S2 as a "wireless switch" (that's how Aqara name this feature in their app). However I am not sure that you can do this even in the Aqara app currently, but only to set both S1/S2 switches as wireless switches or not.

Anyway, a great first step would be to have the switches state separated and visible from the relays.

rvalitov commented 10 months ago

Want to use S1 as a manual button for garage opening/closing and S2 for monitoring the state of the door with a magnetic contact sensor

To use an external button you should connect it to S1/S2 and COM. I use a rocker switch for that. In Zigbee2MQTT there are 3 options for external buttons:

  1. toggle that I suppose is for a button swtich
  2. momentum that I suppose is for a rocker switch
  3. none

For my rocker switch I tried both: toggle and momentum do work OK. Perhaps it's just the state how they are being reported in HA, but I had no issues with opening/closing the garage door with the external button.

If you want to add a contact sensor, indeed there's no way to select operational mode for S1 and S2 separately. But I suppose that toggle mode will work just fine for this case. You just need to set the option operation_mode to decoupled and control manually the actions when S1 and S2 contacts are triggered... As for a connection scheme I think the following should work:

  1. For external switch - connect wires to S1 and COM
  2. For contact sensor - connect wires to S2 and COM

hey guys, I saw the interlock is implemented already in https://github.com/Koenkk/zigbee-herdsman-converters/pull/6554, but works not alright.

In my tests the interlock mode works fine.

lsc597 commented 10 months ago

If you want to add a contact sensor, indeed there's no way to select operational mode for S1 and S2 separately. But I suppose that toggle mode will work just fine for this case. You just need to set the option operation_mode to decoupled and control manually the actions when S1 and S2 contacts are triggered... As for a connection scheme I think the following should work:

  1. For external switch - connect wires to S1 and COM
  2. For contact sensor - connect wires to S2 and COM

That was exactly my plan to make the connections and wiring. But, I have the relay on my test bench right no (only power supplied) and I cannot see anywhere in z2m the state of the switches, only the outputs. And of course that's because the switches are binded to the outputs.

I wanted to suggest an improvement because I saw that Aqara supports the option of having "wireless switches" in their native app (connected via aqara hub), so if you check that and the switches become wireless (not binded to outputs) this means you are able to have different states for the switches and the relays. And ideally, for me, would be to be able to have only one of them as a wireless switch - basically the contact sensor (S2) not to control the output anymore, to be decoupled from the output. And the button (S1) to work as a wired switch directly to the output.

Just wanted to give an idea of improvement, maybe it's possible to be done.

Appreciate all the work that is done already and I am a very happy 6-months old user of zigbee2mqtt!

rvalitov commented 10 months ago

I cannot see anywhere in z2m the state of the switches

I think you can catch it in action event which is triggered when the external button is pressed. However, I'm not sure that it's possible to distinguish here between what source triggered the event - S1 or S2. This should be tested...

rvalitov commented 10 months ago

Ok, here's what I got. The Aqara T2 really reports information from sensors S1 and S2 via zigbee2mqtt - it sends action with value either single_l1 or single_l2 for S1 and S2 sensor respectively. Example: image image

These actions are sent no matter of the operation mode (decoupled or control_relay). And the trigger only works for single tap - double tap or hold are not detected by the relay. However, I have a problem of receiving the state action in HA automation. My example of automation is as follow:

---
alias: "Garage Door Switch"
description: >-
  Controls the garage door switch.

id: "switch.garage.door"
mode: queued
max_exceeded: silent
trace:
  stored_traces: 5

trigger:
  - platform: state
    entity_id: sensor.garage_door_relay_action
action:
  - service: notify.channel
    data:
      message: "Garage relay state change\r\nFrom {{trigger.from_state}} to {{trigger.to_state}}"

This automation never runs. And no issues in logs. Can anyone test that the action trigger works for T2?

lsc597 commented 10 months ago

Great info you provided here, @rvalitov. Yesterday I finished installing my Aqara T2 on the garage door and I will definitely try this next week!

rvalitov commented 9 months ago

I also have some progress in working with the contact sensor. I will share my results after finishing all the tests.

ekurgan commented 9 months ago

Have you been able to get the status of the S1 sensor ? On my side Action is always null btw

Matssa56 commented 9 months ago

I want to use this relay with my gate motor and I'm wondering what signal must go in S1/S2 and COM.

My motor has a control unit that sends the voltage to the motor, I was thinking of connecting the two outputs to S1 or S2 in order to see which pin has 0V and 24v (or maybe 220V, need to test with a multimeter). With this, I'll know if it is closing or opening.

Raphael38210 commented 9 months ago

Bonjour, heureux utilisateur du matériel Aqara je me confronte à un problème que je n'arrive pas résoudre: Je m'explique: J'utilise un relais T2 Aqara en contact sec pour domotiser mon portail, il est brancher sur l'entrée serrure a cle. Lorsque je rajoute ce module sur mon hub Aqara et l'application Aqara je le paramètre en contact sec, bouton momentané. Aucun problème si j'appuie sur le Switch ça ouvre si j'appuie a nouveau ca arrête et si j'appuie encore une fois ca referme. Il fait le boulot que je lui demande. En revanche dans l'optique de supprimer mon hub Aqara j'ai basculer ce module sur zigbee2mqtt avec une clé sonoff zigbee 3.0-P. l'inclusion se passe bien j'ai bien tout les réglages qui apparaissent mais par contre une fois configurer correctement lorsque j'appuie une fois sur le bouton ça ouvre. Et si j'appuie une nouvelle fois ça remet le bouton a l'état initial mais ça fait rien sur le portail, il faut appuyer encore une fois pour stopper la fermeture...idem on appuie derrière ça fait rien et faut encore appuyer pour lancer la fermeture, j'en reviens donc a un problème de réglage mais j'ai essayé tout les modes en dry rien a faire.

Screenshot_20240219-211954

Voici un screen de mes réglages.

Bien cordialement et en vous remerciant.

rvalitov commented 8 months ago

@Raphael38210 Bonjour, si tu ne parles par anglais, utilises Google Translate stp.

I think to fix your problem you should set the operation mode to decoupled and then control the logic via scripts. In my case it works perfectly.

lsc597 commented 7 months ago

I've also noticed on my side that action is taking values "single_l1" or "single_l2" when the S1 or S2 inputs are triggered, but I didn't tried to catch those events. What I noticed is that the time is very short, I think the relay is sending only one message of that type and then puts back action to 'null'.

My current configuration now is that I have a contact sensor connected to S2 input and I am monitoring the door state by watching the output for the S2 input (since my configuration is "control_relay" not "decoupled"). So depending on the the state of the output I can take a decision if the doors is closed or not. However, I noticed a strange behaviour - sometimes the output relay is changing its state one more time after triggering, and this results in an inversed behaviour. In other words, I had some cases when, after triggering the door to close, it was showing open in HA, even tough it was closed in reality. That is because the state of the relay was open instead of closed. I think this is related with the working mode of the relays - PULSE. So for pulse whenever the relay is triggered, it would stay ON for the configured time (let's say 300ms) and then it will go back OFF, but in Z2M I still see the relay as ON. If I trigger it again from state ON to state OFF, it does the same thing: open for 300ms and then closed (I can hear it switching).

My question basically is if this is normal behaviour or is a bug in Z2M? If the relay mode is set to pulse, shouldn't it go back to OFF also in Z2M interface after triggering it?

And also the other thing I have in mind is: is it possible to be able to set the "mode" and "switch type" for each relay an switch independently? Because in my configuration I would need S1 to be momentary (it's a push button which is opening/closing the garage door) and S2 to be toggle (it's the door contact sensor which acts like a toggle switch rather than momentary) and for the outputs L1 should work in PULSE mode and L2 should work in power mode (ON/OFF) so that it can be controlled directly by the contact sensor.

HarvsG commented 7 months ago

Is there any evidence that this device does, or could support binding with a bulb (for use with decoupled mode)

TheRealWaldo commented 6 months ago

I'm having some similar challenges with this device, but my use case is different.

On pairing/configuring, there are a few errors about types not matching (strings where integers are expected, undefined where a 1, 2, or 3 is expected, etc.) from the converter, but it does seem to work, at least partially.

I want to use S1/S2 in dry contact mode, decoupled from both relays. I need to know when contact is made, and when it ends, and so far I am unable to see any state change that would be applicable.

In addition, it is reporting a firmware update (27 to 30), but the update simply will not apply.

Error 2024-04-30 18:17:45Exception while calling fromZigbee converter: Expected one of: 1, 2, 3, got: 'undefined'}
Error 2024-04-30 18:17:45Exception while calling fromZigbee converter: Expected one of: 0, 1, 2, 3, got: 'undefined'}
Error 2024-04-30 18:17:45Exception while calling fromZigbee converter: Expected one of: 0, 1, 3, got: 'undefined'}
Error 2024-04-30 18:17:45Exception while calling fromZigbee converter: Value is not a number, got undefined (undefined)}
TheRealWaldo commented 6 months ago

Just stumbled across some small print on an image that says something along the lines of please note, the device needs to be connected to DC power to use as in wireless switch mode. This was in context of using S1 and S2 as contact sensors.

I'm definitely operating in AC.

BeFygo commented 4 months ago

Is there any evidence that this device does, or could support binding with a bulb (for use with decoupled mode)

I managed to bind the LLKZMK12LM to a group with LWG004 spots. Even in decouple mode the relay switches to the same state as lightbulbs. And only a action change of "" when pressing the connected switch.

Unbinding is impossible because of the errors mentioned by @TheRealWaldo

Even in toggle mode there is a noticeable delay between using the switch and the switching of the relay.

FlipsideAUT commented 2 months ago

My question basically is if this is normal behaviour or is a bug in Z2M? If the relay mode is set to pulse, shouldn't it go back to OFF also in Z2M interface after triggering it?

I have the same Problem: Opening and closing GarageDoor works fine (switchtype: momentary and mode: pulse) - why is it still staying at ON after sending an impulse in Z2M and MQTT & Dashboard. It should behave like a Button not a switch(ON/OFF) in impulse mode i would expect.

pswel1 commented 1 month ago

Hi all, very detailed thread!

had some tips for lumi.switch.acn047 (the T2 relay) on HA (particularly zigbee2mqqt for sure, possibly ZHA)

To get the relay to operate successfully as a dual sensor (ex- garage door open/closed magnetic switches), it has to use AC voltage to power the T2 unit. Then it needs to be in "decoupled" mode in "Exposes", and additionally in "toggle" mode for the switch.

This combination now emits an mqqt code "single_l1" (or l2) when the pin is bridged to COM

But, most garage door magnetic sensors don't work with A/C. So now you need a dual 24V octocoupler relay board. Tap into the garage door transformer or 24V to power a compatible board, or use wall wart from mains to drive the contact sensor's loops and use them to control the relay on the AC side of COM/S1/S2

annoying but finally "does it all" for garage door from a single device.

rvalitov commented 1 month ago

Ok, below is my story how I configured Aqara T2 to work in garage. I've been using it almost for one year, so I guess I can share my experience now. The Aqara T2 module with some limitations is able to:

My setup scheme is below: image

Scheme and comments

  1. Aqara T2 is connected to AC power line, 220V in my case, using terminal points L and N.
  2. Terminal points L1 and LOUT are connected to the garage door opener - your motor/control unit, check your device manual. In manual it's written how to connect a switch that controls the garage door. For most garage motors the logic is simple: when 2 wires are connected for short period of time it gives the signal to the motor to start or stop. After each stop the motor changes the direction: it either opens or closes the door. It's very simple and you don't need to respect the polarity of wires: just connect them to the terminal points in any order. You can first test that your motor works correctly by connecting the wires by hand, and if that works, then connect the wires to Aqara T2.
  3. A light switch is connected to Aqara T2 using terminal points S1 and COM. It does not matter the polarity of the wires, just connect them. It's important to use a light switch which is rocker-type. Visually they look the same. But the logic is that for rocker-type switch there's no "ON"/"OFF" position - every time you push it, the button returns back to normal position, it works like a mouse click. By the way this type of switch can be used directly with the motor, because it allows to send the required "pulse" signal. In my case I use IP54 switch that is perfect for garage environment.
  4. A standard wired magnetic sensor is connected using terminal points S2 and COM. Polarity does not matter. There are lots of magnetic sensors of different forms and shapes. The only difference between them is the logic how they operate: they can be normally opened or normally closed. As a result they provide signal either when they become closed or opened.

The Aqara T2 configuration.

  1. Work mode is pulse. Well, it's obvious that you need this mode to send a short pulse signal to the garage motor.
  2. Switch type is momentary. Someone said here that we must use toggle. I made tests and no other modes than momentary do work and provide desired behavior.
  3. Interlock is OFF, we don't need this in our scenario.
  4. Pulse length is 200 ms - that's default, I didn't change that. It works good.
  5. L1 operation mode: control_relay or decoupled. L1 in Z2M corresponds to the connected switch. I use control_relay. In this case when switch is pressed, the Aqara T2 does everything automatically. However, if you would like to add some advanced logic, for example, if the switch should be ignored sometimes, then you should use decoupled mode and write your own script in HA that will manage all this.
  6. L2 operation mode: decoupled. L2 corresponds to the magnetic sensor. The mode must be decoupled, because you just need to read this data and do not want to pass any command to the motor.

Screenshot: image image image

How to get data when something is triggered in HA? Checking Z2M logs gives us information that when the switch or the magnetic sensor sends a signal to Aqara T2 - we receive action with payload single_l1 (switch click) or single_l2 (magnetic sensor): image

You can write a binary sensor like this to catch the events:

# Binary sensor to detect if the garage door is closed, returns true if closed, false otherwise
- trigger:
    # Magnetic sensor says it's open
    - platform: state
      entity_id: sensor.garage_door_relay_action
      to: 'single_l2'
      id: 'opened'
    # Switch button is triggered, so the door is moving, i.e. the garage door is open or partially open or is stopped in open state
    - platform: state
      entity_id: sensor.garage_door_relay_action
      to: 'single_l1'
      id: 'opened'
  # Think and add some other condition for the "closed" state! I couldn't think of something useful without making this example too complicated.
#   - platform: state
#      entity_id: something
#      to: 'something'
#      id: 'opened'
  binary_sensor:
    name: "Garage door sensor"
    unique_id: garage_door_sensor
    state: >-
      {% if trigger.id == 'closed' %}
        true
      {% elif trigger.id == 'opened' %}
        false
      {% else %}
        unknown
      {% endif %}
    device_class: 'garage_door'

The logic above is very simple and not accurate. The main problem is the magnetic sensor. It is very simple and triggers only one event! I have a standard magnetic sensor that sends the event single_l2 only when the door sensor goes to "open" position. It sends nothing when the sensor goes to "closed" position. Perhaps, you could buy another type of magnetic sensor that will send the signal when it goes to "closed" position - this seems to be more useful. But still does not look secure.

I was thinking that perhaps using an approach with from could do the trick:

 # What if we catch the situation when the magnetic sensor stops sending the "open" action?
    - platform: state
      entity_id: sensor.garage_door_relay_action
      from: 'single_l2'
      id: 'closed'

I was thinking that this approach could help to catch the situation when the sensor goes to "closed" position. However, it does not work like that. Indeed, this part of code will be triggered when single_l1 event happens from the switch and that's not what we need. Also, the magnetic sensor sends only a single single_l2 event, so we can't catch a situation when the sensor "stops" sending them. Also there are no other events like double_l2 or multiple_l2, etc.

Conclusion.

  1. The Aqara T2 controls my garage door perfectly. I tested it almost for a year. I had only one issue when the relay did not respond, but that was my mistake - I connected the relay to the wrong router. After proper reconnection I have about 180LQI and the T2 has been very responsive.
  2. The light switch that I use to control the garage door by hand also works great, no issues.
  3. I think that a single standard wired magnetic sensor is useless, because it sends only one state in a single event. As a result this is not secure and informational. As proof of concept that magnetic sensors can be connected to Aqara T2 and Z2M - yes, that's possible, but it does not work as I would like or expect. I removed this magnetic sensor and use a normal Zigbee door sensor that sends proper events with both states explicitly defined and triggered: opened and closed. Perhaps, if the Aqara T2 integration in Z2M can be improved, the standard wired sensor could become helpful. Another solution is to use 2 magnetic sensors instead of one - one sensor will send signal when it's in "open" state, another one when it's in "closed" state. In this case these 2 sensors will take both S1 and S2 ports, but I need at least one of them to control my garage door, so that's not for me.
pswel1 commented 1 month ago

Hi Ramil, that is an absolutely incredible breakdown which would have saved me a ton of time! It should be an official tutorial 💯

Tiny correction - in point # 4 I believe it's S2 (to correspond with the excellent image)

In my case, exact same setup minus one detail: I'm not using the physical switch; I have just the original RF controller mounted on the wall. (I might switch to Zigbee switch)

Instead I'm using two sensors, so I (should) receive a "single_l1" for closed and a "single_l2" for open. This means the state does update for each full cycle (but is still blind to a partial opening).

However, my primary question is - the COM/S1/S2 seem to be passing AC current (matches voltage across L/N). This wasn't compatible with my magnetic sensors. The mag sensors do work in DC mode, but then the S1/S2 do not recognize a connection to COM when the T2 unit is powered by DC. Are your magnetic sensors working despite AC?

rvalitov commented 1 month ago

@pswel1 thank you for reading and finding the typo about S2! I updated the text.

Instead I'm using two sensors, so I (should) receive a "single_l1" for closed and a "single_l2" for open.

Sure, this will work if you have different sensors (not the same model/version), i.e. one that triggers the "open" state, another one that triggers the "closed" state.

However, my primary question is - the COM/S1/S2 seem to be passing AC current (matches voltage across L/N). This wasn't compatible with my magnetic sensors. The mag sensors do work in DC mode, but then the S1/S2 do not recognize a connection to COM when the T2 unit is powered by DC. Are your magnetic sensors working despite AC?

Good question. Indeed, most magnetic sensor's technical requirements say that they work with 10-30V DC. Some googling shows that there are also AC-compatible magnetic sensors, but it seems rather a rare case. I used a cheap magnetic sensor that costs 2-3$ maximum. I doubt that it is AC-compatible. It has very thin wires, so I think it also proves that it is intended for low voltage and current. However, in my tests it worked. I was testing the sensor not for a long time, perhaps one hour maximum, just to confirm that it works and that there's no way to handle my situation just with one sensor. After that I removed it. During this test the sensor always worked, there were no "false-positive" events, or "missed" events, and the wires, nor the sensor became hot - I checked the temperature. I think the wires should be checked with multi-meter to confirm that it's AC. I'm pretty sure the parameters at S1 and S2 should match the incoming power line: if it's AC then it's AC, if it's DC then it's DC, because T2 does not have any built-in AC/DC transformer. In my tests the sensor only worked in momentary switch type, toggle or none did not pass the events from the sensor.

pswel1 commented 1 month ago

Just to conclude - my mag sensors do not work on AC, except when energizing initially. So I was able to switch to DC using a octoisolator dual relay. Now single_L1 and single_L2 fire correctly!

image

I already had the sensors mounted, and wanted to minimize zigbee traffic for future debugging, so this was better for me.

figuring out this functionality was a detour. Earlier I had misinterpreted that the missing data (the errors shown via Zigbee2Mqtt ,noted above) were the issue. Using debugging mode, I managed to trace the errors to cluster "manuSpecificLumi" with the message data "65522". Hope that's useful. It would be nice to get rid of the errors, but I'm pleased to finally get the status switches working!

SanderDevCode commented 1 month ago

I don't know if its a user error or not but I give it a shot for some help. I have a problem with my roller shutter motor and the LLKZMK12LM. I have a momentary contact switch on the wall to control the roller shutter, which means I need to hold the switch to operate the motor.

I've connected my roller shutter motor to the LLKZMK12LM as follows:

For the switch (momentary switch) connections:

Configuration: Switch type is set to momentary. Mode is set to power. Operation Modes: Both are set to control relay.

I can control the shutters via Zigbee2MQTT (Z2M) just fine, so that part works well. However, the problem arises when using the physical switch. The motor doesn’t start moving while I hold the switch; instead, it starts moving when I release it and continues until I press the switch again. It seems like the relay is in 'toggle' mode, even though I've set it to 'momentary'.

I also occasionally encounter the following error: "z2m: Exception while calling fromZigbee converter: Expected one of: 0, 1, 3, got: 'undefined'".

State:

{
    "consumption": 0.0010999999046325684,
    "current": 0.02,
    "device_temperature": 28,
    "energy": 0,
    "interlock": "ON",
    "led_disabled_night": false,
    "linkquality": 180,
    "mode": "power",
    "operation_mode_l1": "control_relay",
    "operation_mode_l2": "control_relay",
    "power": 0.15,
    "power_on_behavior": "off",
    "power_outage_count": 9,
    "pulse_length": 200,
    "state": "OFF",
    "state_l1": "OFF",
    "state_l2": "OFF",
    "switch_type": "momentary",
    "update": {
        "installed_version": 30,
        "latest_version": 30,
        "state": "idle"
    },
    "voltage": 228.86,
    "action": null,
    "update_available": null
}

Anyone who can give me some tips how to troubleshoot / fix this?

[Update 8th Oct] I've "fixed" my problem after some more testing/debugging

My switch is a momentary switch (hold to keep the motor running), so I thought I need to set the switch type to momentary in z2m. But that doesn't work, it works like a toggle switch (L1 turned on when S1 is toggled - turned on and off).

I've tried to set the switch type to "toggle" in z2m to see what happens... Well It works like it is momentary, L1 is turned on as long as S1 is turned on and stopped directly when S1 is turned off.

Would it be possible this device flipped the default xiaomiSwitchType that is used in the converter?

Switch type none is working as expected: nothing happens.