Code question: sensor state not showing correctly in Home Assistant

I have 5 Sonoff basics flashed with the following Esphome <espbasic.yaml> In Home Assistant the relays respond correctly, but the binary.sensor doesn’t display on/off along with button press. The led on the Sonoff toggles correctly with the relay. Also I get “no state history found” when I select a relay in HA LovelaceUI. I’m sure its a simple fix, but I’m not sure where to look.

substitutions:
  # https://esphome.io/guides/configuration-types.html#substitutions
  # device name lowercase and "_" aloud
  device_name: tasmotabasic5
  friendly_name: Tasmota Basic 5
  ip_address: !secret tasmotabasic5_ip
  # icon: "mdi:lightbulb"
  
esphome:
  # https://esphome.io/components/esphome
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout

wifi:
  # https://esphome.io/components/wifi
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: ${ip_address}
    gateway: !secret wifi_gateway
    subnet: !secret wifi_subnet
    dns1: !secret wifi_dns1

# web_server:
#   port: 80
  # https://esphome.io/components/web_server.html

logger:
  # https://esphome.io/components/logger

api:
  password: !secret esphome_api_password
  # https://esphome.io/components/api

ota:
  password: !secret esphome_ota_password
  # https://esphome.io/components/ota

binary_sensor:
  - platform: gpio
    id: button
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: ${friendly_name} Sensor
    on_press:
      - switch.toggle: ${device_name}_relay
      

switch:
  - platform: restart
    name: ${device_name}_restart
  - platform: gpio
    name: ${friendly_name} Relay
    id: ${device_name}_relay
    pin: GPIO12
    on_turn_on:
      - light.turn_on: ${device_name}_led
    on_turn_off:
      - light.turn_off: ${device_name}_led
    
output:
  - platform: esp8266_pwm
    id: ${device_name}_green_led
    pin:
      number: GPIO13
      inverted: True

here is the code i use for my sonoff basics (old style with solder traces):

esphome:
  name: ${name}
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  reboot_timeout: 0s
  fast_connect: true
  manual_ip:
    static_ip: ${ip}
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    
# Enable logging
logger:

# Enable Home Assistant API
api:
  #password: !secret esphome_api_pwd
  reboot_timeout: 0s

ota:
  #password: !secret esphome_ota_pwd

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    # name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
    on_press:
      - switch.toggle: relay_template
    on_multi_click:
    - timing:
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at least 0.2s
      then:
        - switch.turn_on: restart_sonoff

switch:
  - platform: gpio
    pin: GPIO12
    id: relay
  ## https://esphomelib.com/esphomeyaml/components/switch/template.html
  ## tie the led & relay together & report status regardless of trigger method   
  - platform: template
    name: ${friendly_name}
    id: relay_template
    lambda: |-
      if (id(relay).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - light.turn_on: status_led
      - switch.turn_on: relay
    turn_off_action:
      - light.turn_off: status_led
      - switch.turn_off: relay
    # optimistic: true # this will change the toggle switch to individual on/off buttons
  - platform: restart
    #name: "Reboot Kitchen Sconce Sonoff"
    id: restart_sonoff

output:
  ## https://esphomelib.com/esphomeyaml/components/output/esp8266_pwm.html
  ## create a PWM pin to control
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  ## https://esphomelib.com/esphomeyaml/components/light/monochromatic.html
  ## attach a monochrome light to the PWM pin
  - platform: monochromatic
    # name: "Sonoff Basic Green LED" # uncomment to expose the led as a light with brightness control
    output: basic_green_led
    id: status_led
    default_transition_length: 1ms # controls the light fade/transition time
    
text_sensor:
  - platform: version
    name: ${friendly_name} ESPHome Version
    
sensor:
  - platform: wifi_signal
    name: ${friendly_name} WiFi Signal Strength
    update_interval: 60s