I want to create a template binary sensor from 2 binary sensors, put code like this doesn't work, how should i fix the code?

I want to create a template binary sensor from 2 binary sensors, put code like this doesn’t work, how should i fix the code?

esphome:
name: motion-am312-pavillion
platform: ESP8266
board: nodemcuv2

logger:

ota:
password: “12345678”

wifi:
networks:

  • ssid: SideParkingCH6
    password: 12345678
  • ssid: WashAreaCH2
    password: 12345678
  • ssid: Kitchen
    password: 12345678
  • ssid: TendaCH2
    password: 12345678
  • ssid: kaokai
    password: 12345678

ap:
ssid: “motion-am312-pavillion”
password: “12345678”

captive_portal:

web_server:
port: 80

api:
reboot_timeout: 5min
password: “12345678”

sensor:

  • platform: wifi_signal
    name: motion am312 pavillion Wifi Signal
    update_interval: 10s
  • platform: uptime
    name: motion am312 pavillion Uptime

switch:

  • platform: restart
    name: “motion-am312-pavillion”

binary_sensor:

  • platform: gpio
    pin: D8
    name: “mts am312 pavillion d1”
    device_class: motion

  • platform: gpio
    pin: D2
    name: “mts am312 pavillion d2”
    device_class: motion

  • platform: gpio
    pin: D7
    name: “mts am312 pavillion d7”
    device_class: motion

  • platform: gpio
    pin: D0
    name: “mts am312 pavillion d0”
    device_class: motion

  • platform: gpio
    pin: D5
    name: “mts am312 pavillion d5”
    device_class: motion

  • platform: gpio
    pin: D6
    name: “mts am312 pavillion d6”
    device_class: motion

  • platform: template
    name: “mts pavilion combile”
    lambda: |-
    if (id(mts am312 pavillion d0).state = true) & (id(mts am312 pavillion d7).state = on)
    return true;
    if (id(mts am312 pavillion d0).state = false) & (id(mts am312 pavillion d7).state = false)
    return false;
    }

I have moved your post to the correct category, could you now please edit your post and format your config correctly.

From what I can see from your incorrectly formatted code, you have not given those binary_sensors an id: (id is not the same as name)

1 Like

thank you :grinning: :grinning: :grinning: