Skip to content

Instantly share code, notes, and snippets.

@Palakis
Last active March 3, 2023 14:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Palakis/cf370a19d2a9da38ac0d88776498450c to your computer and use it in GitHub Desktop.
Save Palakis/cf370a19d2a9da38ac0d88776498450c to your computer and use it in GitHub Desktop.
ESPhome on Action LSC Motion Sensor - Tuya TYWE3S (ESP8266-based)
# This device has two chips:
# - an ESP8266-based WiFi Module that talks to Tuya's cloud service (when running the stock firmware) and the on-board MCU.
# - an unmarked Tuya microcontroller (a.k.a MCU) that acts as a power management chip and wakes up the WiFi Module
# when motion is detected by the PIR sensor. The WiFi Module has to talk to the MCU upon power-on to prevent immediate power-off.
substitutions:
device_name: CHANGEME
esphome:
name: '${device_name}'
platform: ESP8266
board: esp_wroom_02 # TYWE3S modules have 2MB of on-board flash
on_boot:
then:
- uart.write: [0x55, 0xAA, 0x00, 0x02, 0x00, 0x01, 0x04, 0x06] # report "wifi ok, connected to router and to cloud"
- wait_until: mqtt.connected
- binary_sensor.template.publish:
id: pir_workspace_motion_detected
state: ON
- delay: 1s
- binary_sensor.template.publish:
id: pir_workspace_motion_detected
state: OFF
- uart.write: [0x55, 0xAA, 0x00, 0x02, 0x00, 0x01, 0x05, 0x07] # power off wifi module
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
fast_connect: True
# Disable serial logging
logger:
baud_rate: 0
# Enable OTA updates
ota:
password: !secret mgmt_pass
time:
- platform: sntp
id: sntp_time
uart:
baud_rate: 9600
tx_pin: GPIO1
rx_pin: GPIO3
mqtt:
broker: !secret mqtt_broker
username: !secret mqtt_username
password: !secret mqtt_pass
discovery: True
# TODO detect motion from MCU messages
binary_sensor:
- platform: template
id: pir_workspace_motion_detected
name: 'PIR Workspace - Motion Detected'
device_class: motion
@Robbe-B
Copy link

Robbe-B commented Mar 3, 2023

@Palakis
This is amazing !
This is my chance to get rid of the default tuya integration issues !
Can you give more information on how you flashed the chip ?
Any change there was also an analog pin assigned for measuring the battery level ?
I believe it will be probably be pin 2 since this is a 10-bit-precision SAR ADC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment