Turn off light that is already off and it blinks momentarily

When I try to send a turn_off message to a light that is already off, it blinks on momentarily before turning off. Is this expected? Easy to fix, but I’m surprised it’s necessary.

Context:

I have a pretty simple automation to manage a pair of lights. The payload for this question is this:

      - action: light.turn_off
        metadata: {}
        target:
          entity_id:
            - light.her_bedside
            - light.his_bedside
        data: {}

…which (if my light is already on) causes it to blink on before turning off. Wut?

The truth table for what I’m trying to achieve is pretty simple:

…which basically says “if you double click your bedside, both lights will end up in the opposite state of the opposite one.” (eg. if I single click the button, my light turns off; if I then double click when hers is on, I want hers to turn off but not affect mine.0)

So the full resulting automation is this (note that I created this through the UI, just showing the YAML here for concision/completeness):

alias: bedside (his) - double click
description: ""
triggers:
  - device_id: cc6647d1732ff02fd85cabbe614dfd2a
    domain: zha
    type: remote_button_double_press
    subtype: button
    trigger: device
conditions: []
actions:
  - type: toggle
    device_id: 42f49ef3f39ed87fa343573b0a8f59b7
    entity_id: 1320fffb43914d7e3df3bd24a4888b80
    domain: light
  - if:
      - condition: state
        entity_id: light.her_bedside
        state:
          - "off"
    then:
      - action: light.turn_on
        metadata: {}
        target:
          entity_id:
            - light.her_bedside
            - light.his_bedside
        data: {}
    else:
      - action: light.turn_off
        metadata: {}
        target:
          entity_id:
            - light.his_bedside
            - light.her_bedside
        data: {}
mode: single

I expected the HA system to recognize that the light was already off and suppress the message, but if it did send the message I expected the light to ignore it, so this was pretty surprising. The manual fix is obvious, but I thought I’d ask before injecting the more complex logic. Anybody have thoughts for what is causing this behavior?

Sounds like poorly programmed firmware in the smart bulb/lamps.

Nope! Problem was that I’m a dumbass. Note this in the automation:

actions:
  - type: toggle
    device_id: 42f49ef3f39ed87fa343573b0a8f59b7
    entity_id: 1320fffb43914d7e3df3bd24a4888b80
    domain: light

D’oh! Sorry for wasting anybody’s time.

It is not supposed to react if it is already in the wanted state.

What is the device being toggled in the automation though? Because it is a device action (avoid those if you can) we cannot tell what entity it operates on. If it is either of the bedside lights it might explain the behaviour.

Ah, I see you saw it too :slight_smile:

Could you expand on why we should use entities rather than devices? And when it might make sense to use a device instead? I’m still a bit vague on when to prefer one over the other.

It is listed as a subject under automations.

1 Like