Weird problems with automation (light/smart plug)

I’m running HA for years now, with no major problems, I guess it’s my turn. :blush:

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?

Possible issue with Tuya smart plug causing netflix apklub the light to turn off by itself and preventing manual control.
Try troubleshooting by checking the plug’s firmware, resetting it, or using a different plug to see if the problem persists.

Reasons I can think of why plugs could log they turned off this way:

  • HA fails to receive the ‘on’ state and thinks the turn_on failed (often communication faillure, how is wifi reception at the place of the plug?)
  • The plug detected a situation like overload or similar and turned off - is it a heavy, or otherwise problematic load?
  • The plug has a setting to turn off x time after activation (try factory reset of the plug)
  • The on/off button on the pug was pressed - is the button pressed by accident?
  • The plug has lost power and has a setting to be off when power returns. Is the plug properly powered all the time or could it be plugged in a faulty socket itself?

I think it’s not Tuya. 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.

1 Like
  • HA fails to receive the ‘on’ state and thinks the turn_on failed (often communication faillure, how is wifi reception at the place of the plug?)

Reception is low, but not abysmal. Everything works fine.

  • The plug detected a situation like overload or similar and turned off - is it a heavy, or otherwise problematic load?

The load is 60W. No problem there.

  • The plug has a setting to turn off x time after activation (try factory reset of the plug)

I did try that. The same hapens.

  • The on/off button on the pug was pressed - is the button pressed by accident?

Nope.

  • The plug has lost power and has a setting to be off when power returns. Is the plug properly powered all the time or could it be plugged in a faulty socket itself?

Not exactly, but got me thinking. Tuya has a setting to resume previous state when power regained. The integration supports this flag. I will now disable it and see how it goes cause maybe it’s a bug in integration or the device itself.

Thanks for the tip.

The Tuya flag “to resume previous state when power regained” is not to blame. Disabled yesterday, and still have the same problem.

I’ve found the source of the problem. While testing Tuya app I made Tuya automation to turn off the plug at 07:00. Eh… human factor as usual…