Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No motion event sent after flahing my motion sensor #18

Open
sebastien247 opened this issue Jun 14, 2020 · 16 comments
Open

No motion event sent after flahing my motion sensor #18

sebastien247 opened this issue Jun 14, 2020 · 16 comments

Comments

@sebastien247
Copy link

Hello,

I flashed my motion sensor and after the reboot, led are turned on for some seconds. But no movement seems to be detected because the blue leds stay off and I receive no event in ESPHome Dashbord. Also, in WireShark I see nothing sent from the Mac address of my ESP, expection for the wifi connection when the sensor is wake up by pushing the button.

NB1: Sorry for my English
NB2: I'm a noob with ESPHome

Thanks for your help.

@ptrooms
Copy link

ptrooms commented Jun 15, 2020

Long story short: once you flashed the PIR sensor you must arrange/ensure that the esp8266 firmware can communicate with the MCU-Pir controller. Remember here that the MCU controlled wait-periods before re-arming the sensor. As such the PiR is (and cannot be used as) not a realtime sensor.

The MCU will power-up the esp8266-board when something is sensed by the PIR but only if the last active (esp8266) trigger was at least 60seconds ago (this re-arming will save battery power).
As long you play with the device on your desk, you will likely move and thus constantly "leave" the PiR in standby mode.

The code flashed inside the esp8266 (ESPhome ?) must initiated WiFi connection and tell the MCU (using the Tuya protocol) for progress (1) Wifi connected, (2) DHCP is requested (3) IP-Address is received and (4) Get state after esp8266 is automatically powerdown.

Note 1: Activity on Wireshark occur when and after the esp8266 power is activated by the MCU-controller and in turn can execute IP/TCP connectivity.
Note 2: Not sure (I use Tasmota for this) if the ESPhome supports the Tuya protocol, if not you must exchange the TuYa protocol commands yourself via the ESPHome interface.

@sebastien247
Copy link
Author

Thanks for your reply ptrooms,

The MCU will power-up the esp8266-board when something is sensed by the PIR but only if the last active (esp8266) trigger was at least 60seconds ago (this re-arming will save battery power).
As long you play with the device on your desk, you will likely move and thus constantly "leave" the PiR in standby mode.

I already try to wait more than 60 seconds to wake-up the esp8266 by motion, but nothing appears.

The code flashed inside the esp8266 (ESPhome ?) must initiated WiFi connection and tell the MCU (using the Tuya protocol) for progress (1) Wifi connected, (2) DHCP is requested (3) IP-Address is received and (4) Get state after esp8266 is automatically powerdown.

How I can check if ESPHome communicates with the MCU?

Note 2: Not sure (I use Tasmota for this) if the ESPhome supports the Tuya protocol, if not you must exchange the TuYa protocol commands yourself via the ESPHome interface.

This repo didn't do that here : https://github.com/brandond/esphome-tuya_pir/blob/master/sb1_uart.h ?

@ptrooms
Copy link

ptrooms commented Jun 15, 2020

@sebastien247
To trigger the PiR into esp8266 one MUST have an initial start that went OK and consist of the MCU modes: WIFI connect, DHCP request, DHCP/IP received and MESSAGE/CLOSE exchange.
Each stage must be send by the esp8266 to the MCU and the esp8266 must read the ACK response.

Th sequence is started by inserting the batteries and forced by doing a long-press (to be sure use > 5 seconds). At the same time you should see something happening on Wifi, DHCP and/or (if wifi/dhcp succeeds) MQTT messaging (which require a connectable MQTT server)

Simultaneously your could connect your RX/GND wires (only) of your USB/rs232 interface to either the TX of RX pin of the es8266 for monitoring (any)conversation.
I use two usb/rs232 devices for this purpose to monitor both he traffic on the RX en TX channel (which after boot, the Tuya sequences are in Hex). In addition I check the VCC powerline of the esp8266.

To keep the PiR silent, I use a wooden box to cover the PiR sensor. Covering with a thin paper/cloth will likely will pass infrared.

I do not use or know indepth ESPhome. Keep in mind that "Tuya" is a widely used protocol to control and supports lots of of wired devices. Tuya also operates low-powerdevices which make them a bit tricky. I strongly recommend to monitor the rs232 during development of happy trouble shooting.

Question: does the esp8266 print logic operates when you connect/power it via the usb (batteries removed) ? Elsewhere you may verify the ESPHome setting required to put the esp8266 into the PiR Tuya mode.

@sebastien247
Copy link
Author

@ptrooms Thanks for your response.

I finaly found the problem, the MQTT was not connected, I wrote the ip with port like this : 192.168.31.215:1883 but the port is not needed.

Also ESPHome Dashboard is not compatible with windows, that's why I have encountered difficulties to progress.

Now my PIR reboot in loop, I try to push the button by a long and a very long press. but always the same think:

[I][sb1:383]: Rebooting: SB1_STATE_RUNNING_OTA
[I][mqtt:202]: MQTT Connected!
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.4 compiled on Jun 18 2020, 23:59:43
[I][sb1:370]: Reset event: 0
[I][sb1:343]: Rebooting: SB1_STATE_EVENT_ACK
[I][app:137]: Rebooting safely...
[I][mqtt:202]: MQTT Connected!
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.4 compiled on Jun 18 2020, 23:59:43
[I][sb1:370]: Reset event: 0
[I][sb1:343]: Rebooting: SB1_STATE_EVENT_ACK
[I][app:137]: Rebooting safely...
[I][mqtt:202]: MQTT Connected!
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.4 compiled on Jun 18 2020, 23:59:43
[I][sb1:375]: Rebooting: SB1_STATE_RUNNING_NORMAL
[I][app:137]: Rebooting safely...
[I][mqtt:202]: MQTT Connected!
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.4 compiled on Jun 18 2020, 23:59:43
[I][sb1:375]: Rebooting: SB1_STATE_RUNNING_NORMAL
[I][app:137]: Rebooting safely...
[I][mqtt:202]: MQTT Connected!
[I][app:058]: setup() finished successfully!
[I][app:100]: ESPHome version 1.14.4 compiled on Jun 18 2020, 23:59:43
[I][sb1:370]: Reset event: 0
[I][sb1:343]: Rebooting: SB1_STATE_EVENT_ACK
[I][app:137]: Rebooting safely...
.....

@ptrooms
Copy link

ptrooms commented Jun 19, 2020

@sebastien247
I presume this reboot loop will continues a few minutes until the MCU (of the PIR) decides to power-off.

Perhaps your MQTT-server may have a Retained (last will) message for the "topic" that's is used... which is re-issed as soon the esp8266 connects to the MQTT server. If possible, monitor/clear/clean MQTT to ensure that message retainment is not playing a role. Best monitor MQTT * ( I use MQTT-explorer) to see what's done there.

Note: keep in mind the're following sequences is to be walked and followed:
A) MCU-level: detects PiR movement powers-up the esp8266 en wait for (up to a maximum 2 minutes) on instructions coming from the esp8266
B) ESP8266-level that: connects to Wifi, get an IP and connects to the programmed MQTT server.
Thereafter the esp8266 should "trick/instruct the MCU sequence:
C) ESP8266 tells MCU via serial/TX it has completed Wifi and check MCU/ack response
D) ESP8266 tells MCU via serial/TX it has completed DHCP request & read MCU/ack response
E) ESP8266 tells MCU via serial/TX it has received an IP request & check MCU/ack response
F) ESP8266 tells MCU via serial/TX it has connected MQTT
immediately thereafter to be completed in about one second:
G) MCU response with movement-acknowledge message that ESP8266 must send to MQTT
H) ESP8266 sends the the response to the connected MQTT server
I) Within about a second, the MCU powerdown the ESP8266
J) MCU wait/can for a 60 seconds period of non-movement before re-arming itself.
Note: step C thru F is done via Tuya protocol message-exchange to fool/trick/interact with the MCU firmware. Step G thru J is beyond your control and the esp8266 will forcily powerdown by the MCU.
By delaying stage srage C thru F, one (here ESPHome) can extend the online-connected period up about 2 minutes.

Seen your log... I presume your ESPHome driven PiR sensor stucks in looping in stage "B" on esp8266 level. The executed Long-press will basically activating (one time only) "stage A"

I suggest, you debug that initial stage B... I myself and I would do this while powering the esp8266 via the usb-cable (without batteries) and by this taking MCU out of the equation as this stage is not yet applicable.

@sebastien247
Copy link
Author

@ptrooms
Thanks a lot for all these details.
I cleared my MQTT server Mosquitto and in fact, some retained messages were present:

[I][app:137]: Rebooting safely...
{"unit_of_measurement":"dB","icon":"mdi:wifi","name":"PIR WiFi Signal","state_topic":"pir/sensor/pir_wifi_signal/state","unique_id":"84f3ebf42bfa-wifisignal","device":{"identifiers":"84f3ebf42bfa","name":"pir","sw_version":"esphome v1.14.4 Jun 18 2020, 23:59:43","model":"PLATFORMIO_ESP01_1M","manufacturer":"espressif"}}
{"unit_of_measurement":"V","icon":"mdi:flash","name":"PIR Battery","state_topic":"pir/sensor/pir_battery/state","unique_id":"84f3ebf42bfa-adc","device":{"identifiers":"84f3ebf42bfa","name":"pir","sw_version":"esphome v1.14.4 Jun 18 2020, 23:59:43","model":"PLATFORMIO_ESP01_1M","manufacturer":"espressif"}}
{"device_class":"motion","name":"PIR Motion","state_topic":"pir/binary_sensor/pir_motion/state","unique_id":"ESPbinary_sensorpir_motion","device":{"identifiers":"84f3ebf42bfa","name":"pir","sw_version":"esphome v1.14.4 Jun 18 2020, 23:59:43","model":"PLATFORMIO_ESP01_1M","manufacturer":"espressif"}}

I also try to monitor serial but all output is unreadable.

Putty Output:
U▒*{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0}▒U▒U▒U▒U▒ftU▒eqPuTTYPuTTYPuTTYPuTTYU▒*{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0}▒U▒U▒U▒U▒ftU▒eqPuTTYPuTTYPuTTYPuTTYU▒*{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0}▒U▒U▒U▒U▒ftU▒eqPuTTYPuTTYPuTTYPuTTYU▒*{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0}▒U▒ftU▒eqPuTTYPuTTYPuTTYPuTTY

Note: I can't boot my PIR alimented only by 3.3v from rs232. I need to use the battery...

@ptrooms
Copy link

ptrooms commented Jun 19, 2020

@sebastien247 , better try hexmode and consider Teraterm which is more practical for HEX mode/display. Using Putty for serialising microcontrollers is no fun.

It appears to me that your babble-fish is the "Product ID Handshake" of the Tuya conversation due to the "get device-id" request (Tuya command 0x55AA00010000 00 (from esp8266 to MCU), as the first communication step. The fact that you see multiple records, tell me that your "esphome" is apparently not seeing this or properly interpreting this as it re-issue "tell me who you are" command.

The >> U▒*{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0}▒U▒U▒U▒U▒ftU▒eq <<
is likely split up into:
??U?* --> Putty mangled header of the packet...
{"p":"Okurono2XLVRV0fB","v":"1.0.2","m":0} --> the MCU Json device type identification
?U?U?U?U?ftU?eq --> Putty mangled trailer checksum byte

You should be able to power the esp8266 itself by the usb/cable, just like flashing. The purpose for this was solely checking out if the esp8266 is doing its thing. (connect wifi, acquire ip and start mqtt ). As you can see the "Okurono2XLVRV0fB" string the esp8266 seems to do its job (so far).
1) "0x55AA0001000000" - which will return that "Okurono2XLVRV0fB"

Your next challenge is to let the esp8266 send the following commandcodes to the MCU:
2) 55 AA 00 02 00 01 02 04 - esp8266 is connected to Wifi (MCU will ack OK)
3) 55 AA 00 02 00 01 03 05 - esp8266 has an IP (MCU will ack OK)
4) 55 AA 00 02 00 01 04 06 - esp8266 is connected to MQTT for status transfer
Note: this is the minimal exchange list, there lots of other combination and more specific "Tuya" commands like low-power mode en even reconfigure device-pinning. Leave this for later, once you have it mastered up and running.

Command/Step 4 will let the MCU return the reason for its activation en implicitly power down the esp8266 in about 1-2 seconds. During that period the esp8266/esphome can tell "mqtt" that is had communication.

Note: for the PiR device its obvious there was PiR-movement as this is the only reason why the PiR will (normally) be powered-up. Other devices, like doorcontact, can differentiate by door-close and door-open response. In addition, one could get a "battery status" response as as result of the long-press-reset-button action.

@sebastien247
Copy link
Author

@ptrooms Thanks again for your answer.
Teraterm is better than putty in fact :-}
Just for peoples reading this thread, to get the result in Hex you must edit TeraTerm.ini and set debug to on "debug=on", after in TeraTerm press "Shift+Esc" to switch in debug mode.

With the result obtained I think I get only the communication from MCU to ESP8266 not the inverse. So it's complicated to understand these messages : 55 AA 00 02 00 00 01 But I deduct that. I obtain 3 times this message so it would seem to be a response for step 2, 3 and 4:
2) 55 AA 00 02 00 01 02 04 - esp8266 is connected to Wifi (MCU will ack OK)
3) 55 AA 00 02 00 01 03 05 - esp8266 has an IP (MCU will ack OK)
4) 55 AA 00 02 00 01 04 06 - esp8266 is connected to Wifi

55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 02 00 00 01 
55 AA 00 01 00 2A 7B 22 70 22 3A 22 4F 6B 75 72 6F 6E 6F 32 58 4C 56 52 56 30 66 42 22 2C 22 76 22 3A 22 31 2E 30 2E 32 22 2C 22 6D 22 3A 30 7D 87 
55 AA 00 05 00 05 66 04 00 01 00 74 
55 AA 00 05 00 05 65 01 00 01 01 71

@ptrooms
Copy link

ptrooms commented Jun 20, 2020

@sebastien247
You're making progress.. well done. Note: I've made a small typo, stage 4) is telling the MCU the esp8266 is connected to Wifi which in turn let

Consider also time stamping the loglines. As far as I know, Teraterm can do that. I do everything on Linux using other scantools/hardware. Consider to probe also the other serial wire, your trace now shows the TX wire of the MCU towards the RX wire of the esp8266. By that you can tell what the esp8266 is asking the MCU.

As You can see, the trace story consist solely of the following (data returned by MCU) patterns:

  • 55 AA 00 01 00 2A 7B .... = response of MCU I'm a PiR sensor
  • 55 AA 00 02 00 00 01 = acknowledge from MCU
  • 55 AA 00 05 00 05 65 01 00 01 01 71 = Motion sensor detected
  • 55 AA 00 05 00 05 66 04 00 01 00 74 = Battery level low
    The normal termination sequence of an orderly execute transaction is:
    55 AA 00 05 00 05 01 04 00 01 00 0F - dpid 01 (=pir) is the cause of activation.

Whatever the reason, the ESPHome firmware seems stuck into phase of interrogating the MCU and either not report or not progressing the MCU/PiR towards state Wifi connected, IP set and closedown message. I do recognize this (low-power device) method by which the esp8266 (esphome) can/will anticipate specific devices.
The question now is, should/will/can/does the ESPHome software recognize these device-codes (65: 01 & 04).

As said before: for a successful operation one must arrange/force the earlier sequence. Without, the MCU considers that this initial- (reset) transaction failed and will - for battery safe reasons - never "arm" the PiR sensor and thus not power-up the esp8266.

Question about your trace: was this after you executed the long press.

@sebastien247
Copy link
Author

@ptrooms
Here is the result with reverse TX / RX:

C8 A4 6C CC C9 E3 A4 24 30 38 F8 48 3C D1 1F F8 FC 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 
55 AA 00 05 00 01 00 05 48 21 88 C8 4C AE FD 44 82 4A BF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 3F 08 C4 AD 08 31 8E 44 82 4A BF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 0E 48 E9 6C EC A8 62 47 43 1E FD 06 78 49 C5 79 F8 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 
55 AA 00 05 00 01 00 05 48 21 88 C8 08 31 A7 8C 0A 48 FF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 48 21 88 D4 28 C8 E2 8C 0A 48 FF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 3F 08 78 C6 08 31 A7 8C 0A 48 FF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 30 64 6E 2C 34 F0 58 6C 64 F8 34 43 38 92 F8 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 
55 AA 00 05 00 01 00 05 48 21 88 C8 08 31 A7 8C 3A C7 FF 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 3F 08 78 C6 08 0A F4 44 48 42 F4 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 48 E5 D6 D4 08 0A F4 44 48 62 3F 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 0E 48 70 70 4B E4 AC 6C 24 F8 3C 42 38 C9 F8 
55 AA 00 01 00 00 00 
55 AA 00 02 00 01 02 04 
55 AA 00 02 00 01 03 05 
55 AA 00 02 00 01 04 06 
55 AA 00 05 00 01 00 05 C6 E5 C4 8D 4C AE FD 44 E4 28 9F 
55 AA 00 01 00 00 00

I have not found the option to time stamp

Question about your trace: was this after you executed the long press.

I don't remember. But with or without long press, the result seems to be equal.

@ptrooms
Copy link

ptrooms commented Jun 22, 2020

@sebastien247
Great, combining things RX+TX: the Tuya communication sequence itself seems to be perfectly OK !!.

55 AA 00 05 00 01 00 05 = esp8266 tells MCU it is in (smart)configmode
<< 55 AA 00 02 00 00 01 = acknowledge from MCU (and wait 30-110 seconds for next action)
55 AA 00 01 00 00 00 = esp8266 asking MCU for devicetype
<< 55 AA 00 01 00 2A 7B .... = response of MCU I'm a PiR sensor
55 AA 00 02 00 01 02 04 = esp8266 tellls MCU the Wifi is active
<< 55 AA 00 02 00 00 01 = acknowledge from MCU (and wait 30-60 seconds for next action)
55 AA 00 02 00 01 03 05 = esp8266 tells MCU got DHCP*****
<< 55 AA 00 02 00 00 01 = acknowledge from MCU (and wait 60 seconds for next action)
. 55 AA 00 02 00 01 04 06 = esp8266 tell MCU it has/connected to MQTT
<< 55 AA 00 05 00 05 66 04 00 01 00 74 = MCU reports DpId Battery level low
<< 55 AA 00 05 00 05 65 01 00 01 01 71 = MCU reports DpId movement as reason
Note all this can be determined using https://docs.tuya.com/en/iot/device-development/access-mode-mcu/wifi-general-solution/software-reference-wifi/tuya-cloud-universal-serial-port-access-protocol

Now some behavior to be sorted out:

  1. After the last message (05 65...), is/will the esp8266 (VCC pin) powered off as it should ?
    Simply wire a multimeter to monitor. After this orderly powerdown, the PiR will wait for 60seconds without movement before -rearming itself.
  2. Do you have any MQTT activity, other than "off/online" ?
    For this use/monitor "mqtt" activity simultaneously with the RX/TX loggin.
    _Note: after the MCU/PiR reports the 05 65, it will wait 2-5seconds before powering-off the esp8266, ESPHome should report that (05 65) status message back via MQTT.

The transaction-sequence in your logging, is repeating. The question is how much time is between those occurrences. Regarding time-stamping, check the Log/setting option. By this you/we can tell the time difference of each repeated sequence.

Aside, I got a feeling that the problem is in ESPHome not sending the last-line state to MQTT. I presume you can confirm that the esp8266 connects to MQTT.. which s not to be confused as valid "sensor-reason" ... though the PiR can only do this if it was powered on.
Mqtt connection leads to an "Online" state fort the device, after MQTT will do/expect keep-alives until these timeout into an "Offline" (Last Will Transaction message-state). Though the Online/Offline state can be used as implicit sensor-detection, this is not the same as actively reporting that "sensor device" was activated due to PiR movement (or battery low detection).

@gairom
Copy link

gairom commented Nov 21, 2020

Hi, I flashed the LSC PIR (via serial port) and I see it connects to hass mqtt but the only msg I get is:

�[0;32m[I][app:105]: ESPHome version 1.15.3 compiled on Nov 21 2020, 03:02:23�[0m

this is the config yaml:

esphome:
  name: lsc_pir
  platform: ESP8266
  board: esp01_1m
  arduino_version: 2.5.1
  board_flash_mode: dout
  includes:
    - sb1_uart.h

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_user
  password: !secret mqtt_pass
  birth_message:
  shutdown_message:
  will_message:

uart:
  - tx_pin: 1
    rx_pin: 3
    baud_rate: 9600
    id: uart0

web_server:
  port: 80

api:
  password: !secret api_password

ota:
  password: !secret ota_password

logger:
  level: INFO
  hardware_uart: UART1

sensor:
  - platform: wifi_signal
    name: "PIR WiFi Signal"
    update_interval: never
    expire_after:
    filters: []
  - platform: adc
    name: "PIR Battery"
    update_interval: never
    expire_after:
    pin: VCC
    filters: []

binary_sensor:
  - platform: template
    id: motion
    name: "PIR Motion"
    filters: []
    device_class: motion
    lambda: "return {};"

custom_component:
  - id: sb1_uart
    lambda: |-
      auto component = new SB1UARTComponent(id(uart0), id(motion));
      return {component};

Also, when I'm connected via the seral port, I can see any logs in ESPHome-Flasher.

Can you please help?

@KirkKirk
Copy link

Hi @ptrooms,

You mention that you using it with tasmota, so I will appreciate it if you can help me to sort out the mess I created.
I use Home Assistant for my home automation and recently bought Tuya PIR sensors. I integrated them with tuya integration but the result is very poor. Sensors are always on or not responding to the movements.
After lots of reading and after I destroyed one PIR, I managed to flash one in tasmota but still not working as I have no idea what next. Wifi is connected, Mqqt is connected, and it is discovered by HA as a device with entities.
Tried all that I could find about Okurono2XLVRV0fB and tasmota and had no luck. Before I gave up, I would appreciate it if you can point on something like a step by step tasmota setup for this sensor.

Thanks in advance

@ptrooms
Copy link

ptrooms commented Sep 19, 2021

Hi @KirkKirk

It's been a while to remember things back. My (I have 3) PIR sensors nicely operate under control of my Domotics (openHAB ) using Tasmota Tuya-device mode. You problem appears to me that your sensor stay (=hardwired) too long active for 2-3 minutes which results in a poor response.
Note: You are using HA with "auto-discovery", not sure if and to what extend that may complicate things. I prefer to start basics things first ( tasmota & mosquitto commands) and when these are OK, work my way up for upper layer integration.

What I've done was first to get things flashed was powering the esp8266 directly (3.3V) while the PIR sensor was covered (to prevent MCU chip activation) and upload standard/generic Tasmota via serial connection.
Via the same serial-connection, I configured the Wifi-SSID & Password (see Tasmota commands for details) which thereafter allows Web browser access to configure the correct MQTT topic etc. Then (still directly powered & PIR covered) I configured the PIR as Tuya device-type TuyaMCU(54), with pins GPIO1/TuyaTX(107) & GPIO3/TuyaRX(108). After this disconnect serial/power-lines, reinsert the batteries (or as I did, connect USB5V to the battery connector which saves batteries)

Thereafter things are are straightforward: when the PIR is activated, it will signal Wifi/MQTT on the defined topic which allows interaction to talk Tasmota 'tuyamcu sequences'. Starting here I deviate a bit from your approach.

When I (my Domotics receives MQTT) detect that the PIR activates by receiving the ONline state, I will instruct immediately the MCU to end the established MQTT session by sending
Tasmota command: Serialsend5 55 AA 00 02 00 01 04 06
(This Tuya mqtt termination sequence is forwarded by the esp8288 via its serial connection to the pir-MCU which confirms by sending a sign-off message, power-down the esp8266, goes to sleep en rearm in absence of movement).
By this my PIR can be (re)armed en trigger in 5 seconds for approx every 30 seconds of silence which is sufficient as response for detection for entry, lights and so on.
Keep in mind the the PIR sensor was not designed for real-time movement detection. It's merely an alarm-device that detects a first movement and then informs its peers.

For all clarity, I'm oldskool and do not talk nor use the specific tuya-command sequences as are nowadays part of newer Tasmota versions which allows for example the auto-detection that simplifies the life of "ones" that do not can/want operate things on a basic level. I do not have the urge to change things (yet). My PIR devices run very old Tasmota (6.7.1) version and I will only update these, if really required. (Update is complicated as the hardware timeout of PIR sensors may interfere beyond functioning and I do not want to re-flash offline that require resolder and so on).

Hope it helps to shine a light and no problem to discuss things further.

@KirkKirk
Copy link

Hi @ptrooms,

Thank you heaps for your guidance. Serialsend5 55 AA 00 02 00 01 04 06 filled the gap missing and works fine now.
The only thing that I would like to know is the template.
I couldn't find anything specific about the model that we have so I used this one:
{"NAME":"Lenovo PIR","GPIO":[255,107,255,108,255,255,0,0,255,255,255,255,255],"FLAG":0,"BASE":54}
and all other settings described here
https://templates.blakadder.com/lenovo_ZG38C02927.html
Does anything better exist and does it will make any difference?

cheers

@ptrooms
Copy link

ptrooms commented Sep 21, 2021

Great to read @KirkKirk it was useful.

For the template, it is just a (positional) template that could sometimes ease, not really here, tasmota configuration:
{"NAME":"Lenovo PIR","GPIO":[255,107,255,108,255,255,0,0,255,255,255,255,255],"FLAG":0,"BASE":54}
that nice name your device with "Lenovo Pir" based upon/as TuyaDevicetype (54) Lenovo PIR witth GPIO1 as TuyaTx(107) , GPIO3 as TuyaRx(108).
The template as such itself will not add nor make functional differences.
Note the blackadder link will use Tasmota-device rules to do things which I prefer, for reasons of access, to have execute in my Domotica-layer.

Note: as gimmick, I've added a DS18B20 sensor to the unused gpio14 pin of the PIR and by setting an extra Tasmota rule ("rule1 on Mqtt#Connected do status 8 endon"), I will also get the temperature in the returned "status8" message during time of movement detection.

Have fun with detections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants