Turning lights off does not work well

Hello,

I do have an automation I hope never need to be triggered. Water leak alert and ligths flash for “bit of a fun”. When there is a leak I know where and respective light flashes in red. It is toggling the light on and off - not working as quick as I imagined but still good enough.

The only thing which really does not work (well in 30% of my tests) is turning the lights off when I “handle” the situation. Which is telling me there is something wrong in the logic. It is hard to recreate the situation as sometimes lights turn off and sometimes they stays on. I added a delay before turning them off as I thought that is the issue but it is still the same. Can you see what is wrong?

alias: voda_flash
description: ""
mode: single
triggers:
  - entity_id:
      - input_boolean.voda_helper
    to: "on"
    id: mokro
    trigger: state
  - entity_id:
      - input_boolean.voda_helper
    to: "off"
    id: sucho
    trigger: state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - mokro
        sequence:
          - repeat:
              sequence:
                - choose:
                    - conditions:
                        - condition: and
                          conditions:
                            - condition: trigger
                              id:
                                - mokro
                            - condition: state
                              entity_id: binary_sensor.sensor_kuchyn_vlhkost_water_leak
                              state: "on"
                            - condition: state
                              entity_id: binary_sensor.sensor_koupelna_vlhkost_water_leak
                              state: "on"
                      sequence:
                        - action: light.toggle
                          target:
                            entity_id:
                              - light.svetlo_kuchyn_ledpasek_linka
                              - light.svetlo_kuchyn_linka
                              - light.svetlo_chodba_koupelna
                          data:
                            rgb_color:
                              - 255
                              - 0
                              - 0
                            brightness_pct: 100
                        - delay:
                            hours: 0
                            minutes: 0
                            seconds: 2
                            milliseconds: 0
                    - conditions:
                        - condition: and
                          conditions:
                            - condition: trigger
                              id:
                                - mokro
                            - condition: state
                              entity_id: binary_sensor.sensor_koupelna_vlhkost_water_leak
                              state: "on"
                      sequence:
                        - action: light.toggle
                          target:
                            entity_id:
                              - light.svetlo_chodba_koupelna
                          data:
                            brightness_pct: 100
                            rgb_color:
                              - 255
                              - 0
                              - 0
                        - delay:
                            hours: 0
                            minutes: 0
                            seconds: 1
                            milliseconds: 500
                    - conditions:
                        - condition: and
                          conditions:
                            - condition: trigger
                              id:
                                - mokro
                            - condition: state
                              entity_id: binary_sensor.sensor_kuchyn_vlhkost_water_leak
                              state: "on"
                      sequence:
                        - action: light.toggle
                          target:
                            entity_id:
                              - light.svetlo_kuchyn_ledpasek_linka
                              - light.svetlo_kuchyn_linka
                          data:
                            rgb_color:
                              - 255
                              - 0
                              - 0
                            brightness_pct: 100
                        - delay:
                            hours: 0
                            minutes: 0
                            seconds: 1
                            milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - mokro
      - conditions:
          - condition: trigger
            id:
              - sucho
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - light.svetlo_kuchyn_linka
                - light.svetlo_kuchyn_ledpasek_linka
                - light.svetlo_chodba_koupelna

The only thing which comes to mind is that you’re unlucky enough to catch the light in the off state when you call the action to turn it off. This would explain why you’re only seeing the issue only around 30% of the time.

You could either change your delay from 3s to something which is not a multiple of 1.5s, or else add another delay of 2s, followed by another light.turn_offaction.

Final option if both suggestions above don’t work - see if the light has an effect you can use for blinking. Most lights support something similar.

Seems I have to get use to be unlucky sometimes :slight_smile: After adding another delay and another turn off action nothing changed. I can actually see in traces that it is triggered but never goes to choose so there might be something missing in that second option. Not sure what though.

Delay changed to whatever duration did not change it either. Effects/Flash seems working but only once, one time it blinked twice. That was actually go to solution I was looking for in the beginning but for some reason those actions are too quick or too slow or the network itself is slow that these commands are not delivered correctly, but all lights are connected directly to coordinator, truth is LQI is pretty low as it is 10 meters away from coordinator, no walls, other lights as routers are on the way. Or maybe I am not doing it right with blink effect. Is it suspicious that both devices from different vendors (Lidl and Tuya) has same named effects?

I would be more leaning towards the lights or the cloud API dropping or not receiving the request. I have all sorts of issues with http lights, zigbee seems somewhat better and Bluetooth is usually flawless.

How are these lights connected to Hass? A local system or routed through the internet via a cloud API?

If the binary sensors state is marked as off at the moment you press the button, your conditions will evaluate to false.

Check the traces again - it should tell you why it stopped at the conditions