Get template value into my binary sensor code

Good morning. I need a little help on this project.

I’m trying to use the following block to let me adjust the “delayed_off” time for my PIR sensor. The goal is to let me adjust the value within home assistant to make it easier to dial in my settings, vs changing and pushing code in esphome constantly.

My problem is I don’t know how to get the number value from the template into the binary sensor. I don’t really understand lambda’s so I have been copy pasting and googling trying to figure it out. So far I can get the code to validate and push to the esphome, but adjusting the template value in homeassistant doesn’t change the delayed_off value for the PIR sensor.

Can someone point me in the right direction?

number:
  - platform: template
    name: "Pir Off Delay"
    id: pir_delay
    unit_of_measurement: s
    min_value: -500
    max_value: 500
    step: 5
    mode: box
    update_interval: 5s
    optimistic: true
    restore_value: true
    initial_value: 0
    icon: "mdi:timer-sand"
    entity_category: config

pir_delay

This gives me the adjustment within HomeAssistant. I can also see the number updating in the esphome logs.

binary_sensor:
  - platform: gpio
    id: pir_sensor
    pin: D7
    name: "Master Bath Motion"
    device_class: motion
    filters:
      - delayed_off: !lambda return int(id("pir_delay"));

I just can’t seem to get the number into the delayed_off: portion. I’ve tried variations of what I have there and at best i can get it to validate and push the code, but it never seems to do anything.

I’ve tried the following variations, among others, but as you can see I don’t really have a clue.

return int(id("pir_delay"))
return id("pir_delay")
return id(pir_delay).state;
return int(id(pir_delay).state); 

As a point of comparison. I’m trying to replicate this setup, which does work, but the setup is a little different. I can’t use the same on_value: … update portion because binary_sensor doesn’t have the .update function apparently.

number:
  - platform: template
    name: "Temperature Offset"
    id: temperature_offset_ui
    unit_of_measurement: "°C"
    min_value: -20
    max_value: 20
    step: 0.1
    mode: box
    update_interval: never
    optimistic: true
    restore_value: true
    initial_value: 0
    icon: "mdi:thermometer"
    entity_category: config
    on_value:
      - lambda: 'id(dht_sensor).update();'

sensor:
  - platform: dht 
    pin: D6
    id: 'dht_sensor'
    temperature:
      name: "Master Bath Temperature"
      id: "dht_temp"
      filters:
        - calibrate_linear:
            - 27 -> 23.77
            - 29.11 -> 26.88
        - lambda: "return x + id(temperature_offset_ui).state;"            
    humidity:
      name: "Master Bath Humidity"
      id: "dht_humidity"
      filters:
        - calibrate_linear:
            - 57 -> 53
            - 52 -> 50
        - lambda: "return x + id(humidity_offset_ui).state;"            
    update_interval: 300s
    model: DHT22   

thank you for the help.

well well. once again, asking the question has lead to the answer

      - delayed_off: !lambda return id(pir_delay).state * 1000.0;

It would seem no quotes on the pir_delay portion and multiplying by 1000 did it. I suspected since it wasn’t given a unit of measurement it was interpreting it as milliseconds. I added the multiplier to get it to seconds. It seems to work now.