forked from blakadder/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTY01
92 lines (63 loc) · 5.22 KB
/
TY01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
date_added: 2020-06-20
title: TY01 Door Window
model: TY01/XCS1
image: /assets/images/TY01.jpg
template: '{"NAME":"TY01","GPIO":[0,107,0,108,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":54}'
mlink:
link: https://www.aliexpress.com/item/4000510216875.html
link2: https://www.aliexpress.com/item/4000492919273.html
flash: serial
category: sensor
type: Contact Sensor
standard: global
---
<div style="float:right; margin:10px; text-align: center;"><img style="width:50px" src="/assets/images/blakapproved.png"> <br><b> by <a href="https://blakadder.com">blakadder</a></b></div>
This is a Tuya battery powered contact (door or window) sensor. Runs on two AAA batteries (not supplied with the device).
This sensor can be found for only 6$ on AliExpress!
Identified with MCU Product ID: `{"p":"3slpirlnlqp0bqo1","v":"1.0.0"}`.

## Flashing
To have best results with this type of device I strongly recommend compiling a stripped down binary. There's an [unofficial binary](https://github.com/tasmota/binaries), compiled from current development release. Flash at your own risk.
### Serial
Easily disassembled by removing the back plate, unscrewing the screw in the battery holder and prying away the plastic using the bottom slot.
The PCB has no visible serial number or other marking on it and a prominent [TYWE3S](https://tasmota.github.io/docs/Pinouts/#tywe3s) module. The broken out pins are for the MCU's 3v3, RX, TX, GND and RST.
MM32F003NW MCU ([datasheet](http://www.mindmotion.com.cn/userfiles/images/MM32F00XiLieWenDang/DS_MM32F003_q_V1.11_EN.pdf)), powers on the Tuya module on reed actuation or on "Reset" bottom button press for a short amount of time sufficient to send opening or closing message.

Due to this design it is difficult to tuya-convert or even configure the device compared to non-battery powered ones. To flash the device solder directly to [TYWE3S](https://tasmota.github.io/docs/Pinouts/#tywe3s) TX, RX, GPIO0, VCC and GND pins (optionally solder GPIO0 to GND but you only need to connect it to GND during boot). You also need to disable the MCU by connecting RST to GND, otherwise you will be unable to flash.

## Configuration
Please read [TuyaMCU](https://tasmota.github.io/docs/TuyaMCU) article to understand the terminology and configuration process.
_If you're using battery power you need to prevent the device from going to sleep by actuating the reed switch constantly (approximately every 5 seconds) during the configuration._ It will be easier to configure everything while the MCU is disabled and [TYWE3S](https://tasmota.github.io/docs/Pinouts/#tywe3s) is powered by the serial-to-USB adapter!
Change device to a TuyaMCU module (or apply the provided template, result is the same)
```console
Module 54
```
Disable multipress button options to prevent a device reset or Wi-Fi AP config mode, disable Power Cycle recovery, turn on TuyaReceived publish to MQTT and set switchmode to follow instead of toggle
```console
Backlog SetOption1 1; SetOption65 1; SetOption66 1
```
Switch the device to battery powered sensor mode (fnId 51):
```console
TuyaMCU 51,51
```
Check with `TuyaMCU` for the following configuration:
```json
{"TuyaMCU":[{"fnId":11,"dpId":1},{"fnId":51,"dpId":21}]}
```
## Functions
Sensor status will be mapped to POWER. ON is "open" and OFF is "closed".
There is no function in Tasmota for battery power dpID so we will use a rule to report battery status (high, medium or low) to a custom topic (change it to any other topic suitable for you).
```console
Rule1 ON TuyaReceived#Data=55AA00050005030400010213 DO publish2 stat/%topic%/BATT high ENDON ON TuyaReceived#Data=55AA00050005030400010112 DO publish2 stat/%topic%/BATT medium ENDON ON TuyaReceived#Data=55AA00050005030400010011 DO publish2 stat/%topic%/BATT low ENDON
```
Don't forget to turn on the rule: `Rule1 1`
## Home Assistant
With Tasmota 9.2+ and integration in Home Assistant 2020.12+ add this rule:
{% highlight yaml %}{% raw %}
rule2 on system#boot do publish2 homeassistant/binary_sensor/%macaddr%_contact/config {"name":"%topic% Door Sensor","state_topic":"stat/%topic%/RESULT","value_template":"{{ value_json.POWER }}","device_class":"door","unique_id":"%macaddr%_contact","device":{"connections":[["mac","%macaddr%"]]}} endon on system#boot do publish2 homeassistant/sensor/%macaddr%_battery/config {"name":"%topic% Battery","state_topic":"stat/%topic%/BATTERY","value_template":"{{ value }}","icon":"mdi:battery","unique_id":"%macaddr%_battery","device":{"connections":[["mac","%macaddr%"]]}} endon
{% endraw %}{% endhighlight %}
Finally disable the switch entity in the device card
## Final Notes
There is a significant delay (~5s on my network with the latest stripped down binary and a static IP) between reed actuation and its MQTT message so I don't recommmend this in critical spots where a fast response is required. I use them on windows where such a delay doesn't matter.
If the batteries are too weak, sensor might be stuck in a bootloop or spawn an ESP-XXXXX AP. The bootloop can reset Tasmota to "factory defaults". You can disable bootloop protection with `SetOption36 0` but that might also put the sensor in a permanent bootloop until the battery dies.