Logic Help | physical light switch as a light group

@armedad after a long debug session and some modification for your code i think we have a winner, documenting here what i noticed for anyone who might see this thread and have similar issues.
TLDR - probably due to usage of Change device type of a switch from switch to light.
All the switches above are configured VIA HACS LocalTuya integration which works flawlessly for me up until this automation flow, no delay or glitches. however while running the code above my light entities (switch converted to light by helper) == 4&7 become unavailable \ unknown which caused the various time delays, and due to the mode single configuration of the automation any new change would not trigger the automation.
I resolved it by removing the helpers and static the switch entities instead.
FYI:

  1. Your description is correct.
  2. The delay was in the light switch LED status but also caused the next automation not to run which was my bigger issue.
  3. knowledge is power, i am a big advocate in having all the information as well - THANK YOU!!!

Adding the current code only running 1± day, so too soon to state the stability:

alias: Sync Switch To Light Group
description: ""
trigger:
  - platform: state
    entity_id:
      - light.all_kitchen_lights
      - switch.all_kitchen_lights
    from:
      - "on"
      - "off"
    to:
      - "on"
      - "off"
condition:
  - condition: template
    value_template: >-
      {{ states.light.all_kitchen_lights.state !=
      states.switch.all_kitchen_lights.state }}
    enabled: true
action:
  - variables:
      trigger_entity: |-
        {%- if trigger.from_state.entity_id  == 'light.all_kitchen_lights' %}
          switch.all_kitchen_lights
        {% elif trigger.from_state.entity_id  == 'switch.all_kitchen_lights' %}
          light.all_kitchen_lights
        {% endif %}
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    target:
      entity_id: "{{ trigger_entity }}"
    enabled: true
mode: single

ah! awesome, that’s great news! the localtuya impact on switch<>light conversion is surprising. i was scratching my head on why my automation would have a 5 sec delay! i still don’t get why that should happen… i think the conversion happens in home assistant, not in localtuya code, so perhaps it’s worth a question by itself…

so if i get it right, at this point, there’s not much for me to do to help right now. just wait and see how it performs for a few days?

2 Likes

@armedad not sure if it was due to localtuya, using a helper to change the entity type or problematic device\WiFi connection but one of those causes the lights status to be unknown before it changed to on\off for some time which caused all the delay.
Editing the above with 1 more minor improvement to limit also from states to on & off to solve cases where a single light is on → unknown (which change the light group state to off) → on which caused all the group light to turn on.

Thank you very much and i hope that was the last issue with that automation :sweat_smile:
Adding the automation as Blueprints hoping it might help anyone else.

2 Likes