Light switch - protection of switching it on when it is bright in the outside

I’m new here and I don’t know how to deal with turning on the light. I would like to turn on the light, but only when the brightness level outside does not exceed 60lux (the light level will be measured by BH1750) - that is, if it is bright outside, the light cannot be turned on - the switch is inactive, and if it gets dark (<=60lux) this light can be turned on. Is it possible to make the switch inactive when certain conditions are met?
Can anyone help me solve this problem?
Thank you.

You’ll need to provide more information - like your yaml showing us how far you have got etc…

But yes - you can test a condition on operation of a switch.

Best done with a momentary button, an on_click trigger and a condition.

Read this, which discusses triggers, actions and conditions:

And while you are at it, read this - all of it:

Below you can find my YAML - for Illuminance <60lux I woudl like to have inactive switch.
I would like to prevent the light from being turned on if it is bright in the outside.

# Example configuration entry
dallas:
  - pin: GPIO23
    update_interval: 10s
i2c:
  sda: GPIO21
  scl: GPIO22
  scan: True
  id: bus_a

sensor:
  - platform: bme280
    address: 0x76
    update_interval: 10s
    temperature:
      name: "Temperatura Sypialnia"
      oversampling: 16x
    pressure:
      name: "Ciśnienie Sypialnia"
    humidity:
      name: "Wilgotność Sypialnia"
  
- platform: dallas
    address: 0x62000008e40e7f28
    name: "Temperatura pokój komputerowy"

  - platform: bh1750
    name: "BH1750 Illuminance"
    address: 0x23
    update_interval: 10s

switch:
  - platform: gpio
    id: relay_switch1
    name: "Lampy zewnętrzne"
    pin: GPIO18

binary_sensor:
  - platform: gpio
    id: physical_button
    pin:
      number: GPIO19
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: relay_switch1

Use a condition. Something like:

binary_sensor:
  - platform: gpio
    id: physical_button
    pin:
      number: GPIO19
      mode: INPUT_PULLUP
    on_press:
      if:
        condition:
          sensor.in_range:
            id: bh1750_illuminance
            above: 50.0    # insert value for the threshold above which you want the relay to operate
      then:
        - switch.toggle: relay_switch1

Thank you very much.
It is solution for binary_sensor - physical button.
But what about “switch” - softwate button? How to make his as inactive when Illuminance is <60lux?

switch:
  - platform: gpio
    id: relay_switch1
    name: "Lampy zewnętrzne"
    pin: GPIO18

That is the output switch. Are you turning that on elsewhere apart from the button (from HA?)

If so, take the condition off the button and add it to the switch like:

switch:
  - platform: gpio
    id: relay_switch1
    name: "Lampy zewnętrzne"
    pin: GPIO18
    on_turn_on:
       if:
        condition:
          sensor.in_range:
            id: bh1750_illuminance
            above: 50.0    # insert value for the threshold above which you want the relay to operate
      then:
        - switch.turn_off: relay_switch1   

binary_sensor:
  - platform: gpio
    id: physical_button
    pin:
      number: GPIO19
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: relay_switch1

Thank you very much, it started working.
There is only one small problem - when the condition is met:

 sensor.in_range:
            id: bh1750_illuminance
            above: 50.0 

And when I turn the switch to the “ON” position, the relay turns “ON” for a moment.
What can be done to make the condition checked before turning the switch to the “ON” position or to make the switch inactive for the condition “above: 50.0”?

Create a template switch, then do the test in that switch. Remove the trigger and action from the relay output and make it internal: true to stop it appearing in HA. Add them to the template switch.

You should be ok based on what you know so far but if you get stuck let us know.