brandond / esphome-tuya_pir

ESPHome support for cheap WiFi PIR sensors
66 stars 21 forks source link

Motion event not captured in HASS #14

Open Papadoma opened 4 years ago

Papadoma commented 4 years ago

I've flashed the pir device with the code here and currently maintain it via the HASSio ESPcomponent

I can see on the log that I get a Reset event: 0 Rebooting: SB1_STATE_EVENT_ACK

any time there's any motion detected which looks like its updating the voltage level, and it does

However, the motion sensor says clear all the time. According to the header file I should be getting a SB1_EVENT_TYPE_MOTION whenever there's motion? But I don't think I am.

simfun commented 4 years ago

Same here: Rebooting: SB1_STATE_EVENT_ACK but no activity in HASS. This is an intercepted message by MQTT Explorer. I am not sure if i have connected it right in HASS.

amitkeret commented 3 years ago

Similar here. My device is constantly getting rebooted, and it happens in two instances: when idle (or booting up), and after a motion event.

I believe the reboot occurs here and here). Granted, I am super-new to ESPHome, UART and also know virtually nothing about C++ programming 😜

A few things I note from the following logs:

Here's my config.yaml

substitutions:
  devicename: mirabellagenio_motion_sensor_01
  friendly_name: Mirabella Genio motion sensor 01
  device_description: Mirabella Genio MS03W Motion Sensor.

esphome:
  name: mirabellagenio_motion_sensor_01
  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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: Genio motion sensor 01 # Not using $friendly_name since it's more than 32 chars :)
    password: !secret AP_Password

captive_portal:

debug:
# Enable logging
logger:
  level: DEBUG
  hardware_uart: UART1

# Web server can be removed after enabling HA API
web_server:
  port: 80

# Enable Home Assistant API
api:
  password: !secret AP_Password

ota:
  password: !secret AP_Password

mqtt:
  broker: !secret mqtt_ip
  username: !secret mqtt_un
  password: !secret mqtt_pw
  birth_message:
  shutdown_message:
  will_message:

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

# Register the Tuya MCU connection
tuya:

sensor:
  - platform: wifi_signal
    name: ${friendly_name} WiFi Signal
    update_interval: never
    expire_after:
    filters: []
  - platform: adc
    name: ${friendly_name} Battery
    update_interval: 30s
    expire_after:
    pin: VCC
    filters:
      - calibrate_linear:
          # Map volts (from sensor) to % (for HA)
          - 2.8 -> 0.0
          - 3.6 -> 100
    unit_of_measurement: "%"
    accuracy_decimals: 0

binary_sensor:
  - platform: template
    id: ${devicename}_motion
    name: ${friendly_name} Motion
    filters: []
    device_class: motion
    lambda: "return {};"

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

Here are two logs:

[I][app:059]: setup() finished successfully!
[D][sb1:185]: state: 11 -> 15 after 14 ms
[I][app:105]: ESPHome version 1.17.2 compiled on May 16 2021, 22:36:29
[C][wifi:443]: WiFi:
[C][wifi:303]:   SSID: *****
[C][wifi:304]:   IP Address: *****
[C][wifi:306]:   BSSID: *****
[C][wifi:307]:   Hostname: *****
[C][wifi:311]:   Signal strength: -50 dB [0;32m▂▄▆█[0m
[C][wifi:315]:   Channel: 11
[C][wifi:316]:   Subnet: 255.255.255.0
[C][wifi:317]:   Gateway: *****
[C][wifi:318]:   DNS1: *****
[C][wifi:319]:   DNS2: (IP unset)
[C][uart_esp8266:075]: UART Bus:
[C][uart_esp8266:077]:   TX Pin: GPIO1
[C][uart_esp8266:080]:   RX Pin: GPIO3
[C][uart_esp8266:081]:   RX Buffer Size: 256
[C][uart_esp8266:083]:   Baud Rate: 9600 baud
[C][uart_esp8266:084]:   Data Bits: 8
[C][uart_esp8266:085]:   Parity: NONE
[C][uart_esp8266:086]:   Stop bits: 1
[C][uart_esp8266:088]:   Using hardware serial interface.
[C][template.binary_sensor:018]: Template Binary Sensor 'Mirabella Genio motion sensor 01 Motion'
[C][template.binary_sensor:018]:   Device Class: 'motion'
[C][logger:185]: Logger:
[C][logger:186]:   Level: DEBUG
[C][logger:187]:   Log Baud Rate: 115200
[C][logger:188]:   Hardware UART: UART1
[D][sb1:350]: Event message of length 18
[D][sb1:352]: 00: 0x65
[D][sb1:352]: 01: 0x01
[D][sb1:352]: 02: 0x00
[D][sb1:352]: 03: 0x01
[D][sb1:352]: 04: 0x01
[D][sb1:352]: 05: 0x67
[D][sb1:352]: 06: 0x02
[D][sb1:352]: 07: 0x00
[D][sb1:352]: 08: 0x04
[D][sb1:352]: 09: 0x00
[D][sb1:352]: 10: 0x00
[D][sb1:352]: 11: 0x00
[D][sb1:352]: 12: 0x55
[D][sb1:352]: 13: 0x66
[D][sb1:352]: 14: 0x01
[D][sb1:352]: 15: 0x00
[D][sb1:352]: 16: 0x01
[D][sb1:352]: 17: 0x01
[I][sb1:358]: Motion event: 1
[D][binary_sensor:036]: 'Mirabella Genio motion sensor 01 Motion': Sending state ON
[D][sb1:185]: state: 15 -> 13 after 245 ms
[C][adc:028]: ADC Sensor 'Mirabella Genio motion sensor 01 Battery'
[C][adc:028]:   Device Class: 'voltage'
[C][adc:028]:   Unit of Measurement: '%'
[C][adc:028]:   Accuracy Decimals: 0
[C][adc:031]:   Pin: VCC
[C][adc:053]:   Update Interval: 30.0s
[C][captive_portal:169]: Captive Portal:
[C][web_server:136]: Web Server:
[C][web_server:137]:   Address: *****
[C][ota:029]: Over-The-Air Updates:
[C][ota:030]:   Address: *****
[C][ota:032]:   Using Password.
[C][api:095]: API Server:
[C][api:096]:   Address: *****
[C][mqtt:051]: MQTT:
[C][mqtt:053]:   Server Address: *****
[C][mqtt:054]:   Username: *****
[C][mqtt:055]:   Client ID: *****
[C][mqtt:060]:   Topic Prefix: 'mirabellagenio_motion_sensor_01'
[C][mqtt:062]:   Log Topic: 'mirabellagenio_motion_sensor_01/debug'
[C][sb1:242]: SB1 UART:
[C][sb1:243]:   Boot Mode: NORMAL
[C][sb1:244]:   Product Info: {"p":"p0y7ucexietpcqlq","v":"1.0.6"}
[C][wifi_signal.sensor:009]: WiFi Signal 'Mirabella Genio motion sensor 01 WiFi Signal'
[C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[C][wifi_signal.sensor:009]:   Unit of Measurement: 'dB'
[C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[C][mqtt.sensor:024]: MQTT Sensor 'Mirabella Genio motion sensor 01 WiFi Signal':
[C][mqtt.sensor:028]:   State Topic: 'mirabellagenio_motion_sensor_01/sensor/mirabella_genio_motion_sensor_01_wifi_signal/state'
[I][sb1:343]: Rebooting: SB1_STATE_EVENT_ACK
[I][app:142]: Rebooting safely...
[D][sb1:392]: SB1 UART shutting down; next boot mode NORMAL

( I'm assuming there was a reboot here and terminal re-connected somewhere along boot process... )

[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.05371 % with 0 decimals of accuracy
[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.05371 % with 0 decimals of accuracy
[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.05371 % with 0 decimals of accuracy
[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.05371 % with 0 decimals of accuracy
[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.17578 % with 0 decimals of accuracy
[D][adc:058]: 'Mirabella Genio motion sensor 01 Battery': Got voltage=3.44V
[D][sensor:099]: 'Mirabella Genio motion sensor 01 Battery': Sending state 80.05371 % with 0 decimals of accuracy
[C][captive_portal:169]: Captive Portal:
[C][web_server:136]: Web Server:
[C][web_server:137]:   Address: *****
[C][ota:029]: Over-The-Air Updates:
[C][ota:030]:   Address: *****
[C][ota:032]:   Using Password.
[C][api:095]: API Server:
[C][api:096]:   Address: *****
[C][mqtt:051]: MQTT:
[C][mqtt:053]:   Server Address: *****
[C][mqtt:054]:   Username: *****
[C][mqtt:055]:   Client ID: *****
[C][mqtt:060]:   Topic Prefix: 'mirabellagenio_motion_sensor_01'
[C][mqtt:062]:   Log Topic: 'mirabellagenio_motion_sensor_01/debug'
[C][sb1:242]: SB1 UART:
[C][sb1:243]:   Boot Mode: NORMAL
[C][sb1:244]:   Product Info: {"p":"p0y7ucexietpcqlq","v":"1.0.6"}
[C][wifi_signal.sensor:009]: WiFi Signal 'Mirabella Genio motion sensor 01 WiFi Signal'
[C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[C][wifi_signal.sensor:009]:   Unit of Measurement: 'dB'
[C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[C][mqtt.sensor:024]: MQTT Sensor 'Mirabella Genio motion sensor 01 WiFi Signal':
[C][mqtt.sensor:028]:   State Topic: 'mirabellagenio_motion_sensor_01/sensor/mirabella_genio_motion_sensor_01_wifi_signal/state'
[C][mqtt.binary_sensor:018]: MQTT Binary Sensor 'Mirabella Genio motion sensor 01 Motion':
[C][mqtt.binary_sensor:019]:   State Topic: 'mirabellagenio_motion_sensor_01/binary_sensor/mirabella_genio_motion_sensor_01_motion/state'
[C][mqtt.sensor:024]: MQTT Sensor 'Mirabella Genio motion sensor 01 Battery':
[C][mqtt.sensor:028]:   State Topic: 'mirabellagenio_motion_sensor_01/sensor/mirabella_genio_motion_sensor_01_battery/state'
[D][debug:023]: ESPHome version 1.17.2
[D][debug:025]: Free Heap Size: 20368 bytes
[D][debug:053]: Flash Chip: Size=1024kB Speed=40MHz Mode=DOUT
[D][debug:190]: Chip ID: 0x002AB040
[D][debug:191]: SDK Version: 2.2.1(cfd48f3)
[D][debug:192]: Core Version: 2_5_1
[D][debug:193]: Boot Version=31 Mode=1
[D][debug:194]: CPU Frequency: 80
[D][debug:195]: Flash Chip ID=0x001540C8
[D][debug:196]: Reset Reason: Software/System restart
[D][debug:197]: Reset Info: Fatal exception:0 flag:4 (SOFT_RESTART) epc1:0x00000000 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000000 depc:0x00000000
[C][tuya:025]: Tuya:
[C][tuya:028]:   Configuration will be reported when setup is complete. Current init_state: 0
[C][tuya:029]:   If no further output is received, confirm that this is a supported Tuya device.
[I][sb1:375]: Rebooting: SB1_STATE_RUNNING_NORMAL