Automatons lights ON OFF

Hi. I have a problem with my light configurations.
What i doing wrong ?
When I try to turn on the button. One light is switched on once, one time two, and once they switch off. randomly.
Thanks

#####KORYTARZ DOL SWIATLO1 ON

  • id: Korytarzdol1ON
    alias: ‘Korytarzdol1ON_Przycisk’
    trigger:
    • platform: event
      event_type: click
      event_data:
      entity_id: binary_sensor.wall_switch_left_158d0001833f08
      click_type: single
      condition:
    • condition: state
      entity_id: light.yeelight_white_34ce0081010
      state: ‘off’
      entity_id: light.yeelight_white_286c07f12ec6
      state: ‘off’
      action:
    • service: homeassistant.turn_on
      entity_id: light.yeelight_white_34ce0081010
      entity_id: light.yeelight_white_286c07f12ec6

#####KORYTARZ DOL SWIATLO1 OFF

  • id: Korytarzdol1OFF
    alias: ‘Korytarzdol1OFF_Przycisk’
    trigger:
    • platform: event
      event_type: click
      event_data:
      entity_id: binary_sensor.wall_switch_left_158d0001833f08
      click_type: single
      condition:
    • condition: state
      entity_id: light.yeelight_white_34ce0081010
      state: ‘on’
      entity_id: light.yeelight_white_286c07f12ec6
      state: ‘on’
      action:
    • service: homeassistant.turn_off
      entity_id: light.yeelight_white_34ce0081010
      entity_id: light.yeelight_white_286c07f12ec6

Next problem …
When I press the button, the light turns on and the automatic is inactive. But when I press a second time, it does not come back to back position (automatic light).

#####KORYTARZ GORA SWIATLO ON AUTO

  • id: KorytarzgoraautoON
    alias: Swiatlo na ruch w korytarzu gora ON
    trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d000132ebe6
    to: ‘on’
    condition:
    • condition: state
      entity_id: sun.sun
      state: ‘below_horizon’
      action:
      service: homeassistant.turn_on
      entity_id: light.yeelight_white_286c07b1b876
      data:
      brightness: 1

#####KORYTARZ GORA SWIATLO OFF AUTO

  • id: KorytarzgoraautoOFF
    alias: Swiatlo na ruch w korytarzu gora OFF
    trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d000132ebe6
    to: ‘off’
    action:
    service: homeassistant.turn_off
    entity_id: light.yeelight_white_286c07b1b876

#####KORYTARZ GORA SWIATLO ON

  • id: KorytarzgoraON
    alias: ‘KorytarzgoraON_Przycisk’
    trigger:
    • platform: event
      event_type: click
      event_data:
      entity_id: binary_sensor.wall_switch_left_158d000183f4d7
      click_type: single
      action:
    • service: homeassistant.turn_on
      entity_id: light.yeelight_white_286c07b1b876
      data:
      brightness: 255
    • service: homeassistant.turn_off
      entity_id: automation.swiatlo_na_ruch_w_korytarzu_gora_off

#####KORYTARZ GORA SWIATLO OFF

  • id: KorytarzgoraOFF
    alias: ‘KorytarzgoraOFF_Przycisk’
    trigger:
    • platform: event
      event_type: click
      event_data:
      entity_id: binary_sensor.wall_switch_left_158d000183f4d7
      click_type: single
      condition:
    • condition: state
      entity_id: light.yeelight_white_286c07f12626
      state: ‘on’
      action:
    • service: homeassistant.turn_off
      entity_id: light.yeelight_white_286c07b1b876
    • service: homeassistant.turn_on
      entity_id: automation.swiatlo_na_ruch_w_korytarzu_gora_on

It’s really hard to make heads or tales of what your automations are without code blocks (see the blue text at the top of your page).

I can tell you this:

This code:

service: homeassistant.turn_on
entity_id: automation.swiatlo_na_ruch_w_korytarzu_gora_on

and

service: homeassistant.turn_off
entity_id: automation.swiatlo_na_ruch_w_korytarzu_gora_off

is what is enabling and disabling your automation.

#####KORYTARZ GORA SWIATLO ON AUTO

id: KorytarzgoraautoON
alias: Swiatlo na ruch w korytarzu gora ON
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d000132ebe6
to: 'on’
condition:
condition: state
entity_id: sun.sun
state: 'below_horizon’
action:
service: homeassistant.turn_on
entity_id: light.yeelight_white_286c07b1b876
data:
brightness: 1

#####KORYTARZ GORA SWIATLO OFF AUTO

id: KorytarzgoraautoOFF
alias: Swiatlo na ruch w korytarzu gora OFF
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d000132ebe6
to: 'off’
action:
service: homeassistant.turn_off
entity_id: light.yeelight_white_286c07b1b876