Need help with code writing

Hi guys. I am trying to make a controller for air compressor. It will consist of two parts: one device with pushbutton and it will send http command to another device which has pressure sensor on A0 and binary output on GPIO2. I have pasted a current code here, which monitors air pressure. But i don’t know how to make so when i send command “turn on”, it would read sensor and command GPIO2 accordingly. And when i send command “turn off”, it would still monitor pressure, but keep GPIO2 off. Any help much appreciated, thank you.

output:
  - platform: gpio
    pin: GPIO2
    id: led_1

light:
  - platform: binary
    name: "pressure"
    id: light_1
    output: led_1

              
  - platform: adc
    pin: A0
    filters:
    - multiply: 3.3
    update_interval: 10s
    id: pressure
    on_value_range:
        - below: 2.55
          then:
            - light.turn_on: light_1
        - above: 3.26
          then:
            - light.turn_off: light_1

Don’t know how correct is this code, but at least this works. Any opinions?

output:
  - platform: gpio
    pin: GPIO2
    id: led_1

  - platform: gpio
    pin: GPIO5
    id: led_2
   

light:
  - platform: binary
    name: "pressure"
    id: light_1
    output: led_1
    

switch:
  - platform: output
    name: "trig"
    id: light_2
    output: led_2
    on_turn_on:
     then:
      - logger.log: "TURN ON!"
      - if:
         condition:
           lambda: 'return id(pressure).state < 1.5;'
         then: 
         - logger.log: "LOW PRESSURE!"
         - light.turn_on: light_1
         
    on_turn_off:
     then:
      - light.turn_off: light_1
      - logger.log: "TURN OFF!"


  
sensor:
  - platform: adc
    pin: A0
    filters:
    - multiply: 3.3
    update_interval: 1s
    id: pressure
    on_value_range:
      - below: 1.5
        then:
        - if:
           condition:
             lambda: 'return id(light_2).state == true;'
           then:
            - logger.log: "LOW PRESSURE!"
            - light.turn_on: light_1
           
   
      - above: 2.8
        then:
         - logger.log: "HIGH PRESSURE!"
         - light.turn_off: light_1

Took me only 5 hours…