Force light switch (Tuya) to remain on

I know the docs says this is fine, but try this:

service: switch.turn_on

Are you getting any errors in your logs? Can you turn it back on by manually making the service call using the developer tools (or if you have a button for this on your UI)?

EDIT: Woops, I missed the obvious:


    action:
      - service: homeassistant.turn_on
        target:
          entity_id: switch.64038777a4cf12d20030_2

Hi, thanks for the reply.

Changed to what you said (in edit lol) but has made no difference, also nothing in logs.

…and yes I can change manually as well.

Any ideas?

FYI log:

2021-08-14 23:11:40 ERROR (MainThread) [frontend.js.latest.202108090] https://xxxxxxxxx.ui.nabu.casa/lovelace/default_view:0:0 Uncaught

2021-08-14 23:12:13 WARNING (MainThread) [homeassistant.components.cloud.google_config] Error reporting state - 5: Requested entity was not found.

2021-08-14 23:12:33 ERROR (MainThread) [frontend.js.latest.202108090] https://xxxxxxxxxx.ui.nabu.casa/lovelace/default_view:0:0 Uncaught

2021-08-14 23:13:10 ERROR (MainThread) [frontend.js.latest.202108090] https://xxxxxxxxxx.ui.nabu.casa/lovelace/default_view:0:0 Uncaught

2021-08-14 23:13:31 WARNING (MainThread) [homeassistant.components.cloud.google_config] Error reporting state - 5: Requested entity was not found.

i am confuse, is it


action:
      service: homeassistant.turn_on
      entity_id: switch.64038777a4cf12d20030_2

or


action:
      service: switch.turn_on
      entity_id: switch.64038777a4cf12d20030_2

that you have now in your yaml?
i would check the name of the switch, usually when it have a “_2” means it created a second instance for some reason

What is the automation’s state? Is it on?

Hi - I have tried both, switch and h…a… but no difference. It’s labeled as …20030_2 as it’s the middle switch of a 3 gang light switch.

And, yes the automations state in ON…

Can you try this

- alias: test
  trigger:
    platform: state
    entity_id: switch.64038777a4cf12d20030_2
    to: 'off'
    for:
      seconds: 5
  action:
    - service: switch.turn_on
      entity_id: switch.64038777a4cf12d20030_2

Ummmm that knocked out Zigbee… and unfortunately didn’t work.

Hmmm cant see how that automation got anything to do with the integration?

I removed the “- alias” for some reason HA does not like that command??

Still doesn’t work though lol, but Zigbee doesn’t fail…

You beat to a reply lol - as above, “alias” is casing issues??

all your automation are in seperate “automation.yaml” ?

Ah ha… for some reason it is now working, I have no idea lol. And yes just one automation file.

Many thanks for all you help folks, have a fabulous day!

FYI, this is what I entered to automation.yaml for anyone else who has this issue:

- alias: "Bathroom LED Switch always ON"
  trigger:
    platform: state
    entity_id: switch.64038777a4cf12d20030_2
    to: 'off'
    for:
      seconds: 5
  action:
    - service: switch.turn_on
      entity_id: switch.64038777a4cf12d20030_2

Oh no… update. If I switch the light switch off via HA everything works perfectly however, if I switch it off via the Tuya light switch it does not get switched back on?

Any ideas on this? Thanks folks.

That mean HA do not get the state update from the Tuya intergration. or delay? so the switch.64038777a4cf12d20030_2 state never change to “off” hence automation not triggered.

Similar issue here…

Tuya devices stopped changing state - Configuration - Home Assistant Community (home-assistant.io)

Aye, it updates on Lovelace but automation doesn’t detect - will have a look at the link…

Hi - after up to 15mins it does reset, so going to look at Tuya local installation. Tuya’s cloud is way too slow in updating HA. Will post update when sorted…

Update: setup Tuya Local and now switches back on straight away - yippee! So, after some digging it appears that the Tuya servers are very slow in communication with HA; however, it does work but takes around 15mins.

But, the plot thickens…

There are two smart bulbs connected to the switch, and come on by PIR activation. But if the switch goes off, when switched back on by HA they come on - using regular Tuya integration my code switched them off which is correct. i.e. they only come on when the PIR detects movement.

Now, using local Tuya, the LEDs do not switch off and can’t be switched off via HA at all.

Code as below - any ideas peeps?

- alias: Bathroom LED Switch - always on
  trigger:
    platform: state
    entity_id: switch.local_tuya_bathroom_leds
    to: 'off'
    for:
      seconds: 5
  action:
  - service: switch.turn_on
    entity_id: switch.local_tuya_bathroom_leds
  - service: light.turn_off
    entity_id: light.bathroom_led_l
  - service: light.turn_off
    entity_id: light.bathroom_led_r

switch name might change in the UI?

Nope lol - all correct.

If I try and switch off the LEDs on Lovelace it shows them as already off - switch them on then off makes no difference (LEDs remain on), switch them on and leave in that state within a couple of seconds they switch to off, but the LEDs remain on.

I have no idea what’s going on here… lol

Found the issue why the bulbs would not respond - my USB Zigbee sniffer needed resetting, think it had got stuck? All working now.

Folks, really appreciate your help on this. Thank you.