Problem with automation and light

Hello,
i’ve added almost all my sensor and switch to Home Assistant, now i’m working with automation, for example i’ve 2 room (camera = bedroom, salotto = livingroom) configured in the same way, one yeelight wifi bulb (that are discovered automatically) and two xioami switch, the configuration of the automation is the following

- alias: "pulsante salotto"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d00019cac0e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0002132e84
        click_type: single
  action:
    - service: light.toggle
      entity_id: light.yeelight_rgb_34ce008b644c

- alias: "pulsante camera"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d000213431e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0001c202e6
        click_type: single
  action:
    - service: light.toggle
      entity_id: light.yeelight_rgb_34ce0084b045

the problem is that if i click one of the “salotto” switch the “salotto” light turn off and the “camera” light turn on
same for the switch in the other room, if i click one it will toggle both the light

if i remove one of the two automation the switch will toggle only one of the light (the correct one), but as you can see the id of the switch are all different and also of the light, did i miss something or have i done something wrong ?

any suggestion ?

thanks

Try using light.turn_on and light.turn_off in action service.

So to split every automation in two, with a condition to check the light state?

Yes try that. It’s much simpler.

I’ve tried that:

- alias: "pulsante salotto on"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d00019cac0e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0002132e84
        click_type: single
  condition:
    - condition: state
      entity_id: light.yeelight_rgb_34ce008b644c
      state: 'off'
  action:
    - service: light.turn_on
      entity_id: light.yeelight_rgb_34ce008b644c

- alias: "pulsante salotto off"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d00019cac0e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0002132e84
        click_type: single
  condition:
    - condition: state
      entity_id: light.yeelight_rgb_34ce008b644c
      state: 'on'
  action:
    - service: light.turn_off
      entity_id: light.yeelight_rgb_34ce008b644c
- alias: "pulsante camera on"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d000213431e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0001c202e6
        click_type: single
  condition:
    - condition: state
      entity_id: light.yeelight_rgb_34ce0084b045
      state: 'off'
  action:
    - service: light.turn_on
      entity_id: light.yeelight_rgb_34ce0084b045

- alias: "pulsante camera off"
  trigger:
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d000213431e
        click_type: single
    - platform: event
      event_type: click
      event_data:
        event_id: binary_sensor.switch_158d0001c202e6
        click_type: single
  condition:
    - condition: state
      entity_id: light.yeelight_rgb_34ce0084b045
      state: 'on'
  action:
    - service: light.turn_off
      entity_id: light.yeelight_rgb_34ce0084b045

but still same beavier when i click every button both the light will toggle, in can that as those light are discovered automatically? because if i try to add it manually in the configuration nothing change, still the 2 automatically deteced will show up

please help me because i relly don’t know what to do

Why do you have two different triggers in each automation?

And why are the same triggers to turn on and turn of? This one is why you have the same behavior…

Because I have two switch in every room that have to control the light
So that’s why same trigger for on and off, but the same trigger it’s only on the same room, so same light I don’t understand why one trigger will turn off/on the other light

I was also thinking that the Id of the switch are wrong but in that case one switch it will only control the other room light, I don’t understand why both

Can you tell me.the name of the buttons on each room and you want them to do?

ok, i have 2 switch in living room:

binary_sensor.switch_158d00019cac0e
binary_sensor.switch_158d0002132e84

that have to turn on and off 1 light:

light.yeelight_rgb_34ce008b644c

in the other room, bedroom i have two switch:

binary_sensor.switch_158d000213431e
binary_sensor.switch_158d0001c202e6

that have to turn on and off 1 light:

light.yeelight_rgb_34ce0084b045

the problem is that when i add the second automation, some goes wrong and every switch toggle both the light

UPDATE:
again i would like to point out that with this configuration:

  - platform: yeelight
    automatic_add: false
    devices:
      192.168.1.4:
        name: Luce Salotto
      192.168.1.3:
        name: Luce Camera

i will not get the two light with the name that i insert here, but i see the two light with the id:

yeelight_rgb_34ce008b644c
yeelight_rgb_34ce0084b045

bu again then it’s like they work together in a group (that i haven’t defined, but what happen to one light, also happend to the other, but only if i have both in the automation file)

i’ve probably found the problem:

here in the trigger, i’ve written event_id instead of entity_id …
now it seems to work great :smiley:

thanks a lot for your support

1 Like

You’re welcome but you did it yourself… :grinning: