[HELP]Automation with lux

I have an old smart LED tv which don’t have CEC functionality so i am trying to do some automation using ESPHome natively so i can automate my TV based on mi box status

When i turn on/off mi box , there is LED indicator I have hooked LDR on that to get its on/off status (i could get status from Home assistant but sometimes i use mobile data too instead of WiFi)

So i want to do automaton based on Lux
if lux value is higher than 100 then turn on “kitchentv” (relay power on)
1 second delay
turn on"sonyp" (IR power on)

and lux value is lower than 100 then turn off “sonyp” (IR power off)
1 second delay
turn off “kitchentv” (relay power off)

i know about using lambda with switch but not getting how to it using lux value

here is my config

esphome:
  name: ir_remote
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "ssid"
  password: "pass"

web_server:
  port: 80

api:

ota:

# Example configuration entry
remote_receiver:
  pin: GPIO15
  dump: all

remote_transmitter:
  pin: 5
  carrier_duty_percent: 50%

sensor:
  - platform: adc
    pin: A0
    id: mibox_lux
    name: "Mi box Brightness"
    unit_of_measurement: lx
    update_interval: 1s
    filters:
      - lambda: |-
          return (x * 5 / 10000.0) * 2000000.0;

switch:
  - platform: gpio
    id: kitchentv
    name: "Kitchen TV"
    inverted: True
    pin: 14
    restore_mode: ALWAYS_OFF

#IR stuff
  - platform: template
    id: sonyp
    name: "Sony Power Button"
    turn_on_action:
      - remote_transmitter.transmit_raw:
         code: [2393, -609, 1192, -610, 593, -608, 1193, -609, 593, 
-608, 1193, -609, 592, -609, 591, -610, 1194, -609, 591, -610, 591, 
-610, 592, -609, 593, -10000]
         carrier_frequency: 38khz
         repeat: 5

By the way your lambda is unnecessarily long. 5/10000*200000 is 1000, just multiply by 1000!

thank you for docs link and your input , working perfectly :smiley: