ESPHome S31 Configuration

Hi,

I have flashed a Sonoff S31 with ESPHome and have the configuration below working for me:

#The substitution block has all the configurable details
substitutions:
  name_of_board: switchs3101
  ota_password: !secret ota_switch_01
  ap_point: !secret ssid_switch_01
  ap_point_password: !secret ssid_switch_01_passowrd
  api_password: !secret switch_01_api_password
  api_encryption_key: !secret switch_01_api_encryption_key
  binary_sensor_name: "Switch-01 Button"
  relay_name: "Switch-01 Relay"
  sensor_name_current: "Switch-01 Current"
  sensor_name_voltage: "Switch-01 Voltage"
  sensor_name_power: "Switch-01 Power"
  updates: "60s" 
  
############################################
#YOU SHOULD NOT NEED TO EDIT BELOW THIS LINE
############################################
esphome:
  name: $name_of_board
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret ssid
  password: !secret ssid_password
  fast_connect: True
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: $ap_point
    password: $ap_point_password

# Enable logging
logger:

uart:
  rx_pin: RX
  baud_rate: 4800

# Enable Home Assistant API
api:
  password: $api_password
  encryption:
    key: $api_encryption_key

ota:
  password: $ota_password


binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: $binary_sensor_name
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    name: $relay_name
    pin: GPIO12
    id: relay

sensor:
  - platform: cse7766
    update_interval: $updates
    current:
      name: $sensor_name_current
    voltage:
      name: $sensor_name_voltage
    power:
      name: $sensor_name_power

status_led:
  pin:
    number: GPIO13
    inverted: yes

I am connecting it to my dishwasher so that I can track the usage (time, frequency and power consumption pattern) over time. So I need this device to be “on” all the time so that we can dishwasher without having to go to HA UI. But whenever it reboots or updates the relay turns off and had to be manually turned “on”.

Also tried adding “restore_mode: ALWAYS_ON” in the binary_sensor section for the relay but I get a syntax error (invalid option).

Is there a way to set default relay setting to “on” instead of “off”?
Thanks,

Pankaj

My bad, I was adding “restore_mode: ALWAYS_ON” in the secton for binary_switch but moving it to switch solved the problem

switch:
  - platform: gpio
    name: $relay_name
    pin: GPIO12
    id: relay
    restore_mode: ALWAYS_ON