tuya / tuya-home-assistant

Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
MIT License
871 stars 206 forks source link

Weird problems with automation (light/smart plug) #926

Closed imbehind closed 1 year ago

imbehind commented 1 year ago

I'm running HA for years now, with no major problems, I guess it's my turn. 😊

Recently, I've changed some hardware - switched from Broadlink IR blaster / IR plug to Tuya Smart plug on 2 of my devices - 2 lights (hydroponics and aquarium).

configuration.yaml

light:
  - platform: switch
    name: Grow Light
    # entity_id: switch.ir_plug_1
    entity_id: switch.wifi_plug_2_socket_1
  - platform: switch
    name: Shrimp Light
    # entity_id: switch.ir_plug_2
    entity_id: switch.wifi_plug_3_socket_1

(old configuration is commented)

this is automation.yaml for Hydroponics. The other one for Aquarium is the same:

- id: '1614469556440'
  alias: 'IR Plug #1 - Hidroponika Kitchen - OFF'
  trigger:
  - platform: time
    at: '22:00:00'
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.wifi_plug_2_socket_1
  mode: single
- id: '1614469602693'
  alias: 'IR Plug #1 - Hidroponika Kitchen - ON'
  trigger:
  - platform: time
    at: 07:00:00
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.wifi_plug_2_socket_1
  mode: single

The problem is that this light (Hydroponics) is turning off by itself, few seconds after it turns on triggered by automation.

The log book says:

Wifi Plug #2 turned off
7:00:15 AM - 13 hours ago
Wifi Plug #2 turned on triggered by automation IR Plug #1 - Hidroponika Kitchen - ON triggered by time
7:00:03 AM - 13 hours ago

Also, when it fails like this and turns itself off, if I try to manually turn ON the light entity on dashboard the switch won't "flip" (it goes straight back to off). The same is when I try to manually turn ON the switch entity on dashboard.

The question is what triggers switch to turn off?

The other (the same) automation for Aquarium works fine, this one also works fine after HA reset, and starts misbehaving again later.

Any ideas how to troubleshoot this?

Tuya Smart Plug Main Module v1.3.5 Tuya Smart Plug MCU Module v1.3.5

imbehind commented 1 year ago

The device log on iot.tuya.com reads:

2023-05-11 07:00:15 Report  Switch 1    OFF device itself
2023-05-11 07:00:03 Report  Switch 1    ON  device itself   
2023-05-11 07:00:03 publish by cloud api    publish by cloud api    success open api    cloud2cloud
2023-05-11 07:00:03 Publish Switch 1    ON

The OFF source at 2:00:15 seems to be "device itself" which appears without previous api call, as with automation at 7:00:03.

The normal sequence (7:00:03) consists of three steps - 1) iot.tuya.com receives request to turn ON (source cloud2cloud), 2) event is published through open api (source open api) and 3) the device confirms it turned itself ON (source device itself).

What I'm saying is that if Tuya smart plug by itself just went off, without any interaction and consequences on HA, I would focus on Tuya itself. But the problem is that HA reflects the change and whatsmore I just cannot manually flip the HA dashboard switch. It reverts to previous state automatically and instantaneously.

imbehind commented 1 year ago

Is it possible the problem arises because of "Power on behaviour" setting under devices is set to "Remember last state"?

Any other ideas?

imbehind commented 1 year ago

I've found the source of the problem. While testing Tuya app I made Tuya automation to turn off the plug at 07:00.