POWR 20A - relay on at startup

I have been searching like a crazy to find a solution here.
I want the switch relay at this device to turn on as default at startup (similar like how you can set a shelly)
But after countless hours scrolling through forums and vibecoding, i still don’t have a working solution.

substitutions:
  update_interval: 2s
  relay_restore_mode: RESTORE_DEFAULT_ON

esphome:
  name: powr01
  friendly_name: POW Elite01 20A
#  on_boot: # Set the initial state of the template switch to the actual relay state. This will NOT change the state.
#    priority: 250.0 # Wait until WiFi is connected to allow the sensor some time to settle
#    then:
#      - delay: 2s
#      - if:
#          condition:
#            lambda: 'return id(v_sensor).state > 10;'
#          then:
#            - switch.turn_on: relay_1
#          else:
#            - switch.turn_off: relay_1



esp32:
  board: nodemcu-32s
  framework:
    type: esp-idf


globals:
  - id: relay_last_state
    type: bool
    restore_value: true
    initial_value: 'true'


# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:
  encryption:
    key: "4qeZaq8NmGswDHW7sWQmJsMP5SaUIqb4iwBYaCBiRk4="

ota:
  - platform: esphome
    password: "0fe85abf0e040d649b3412951c53655a"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Powr01 Fallback Hotspot"
    password: "8whhDAQ6pnsc"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

uart:
  rx_pin: GPIO16
  baud_rate: 4800
  parity: EVEN

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: cse7766
    current:
      name: Current
      id: a_sensor
      filters:
        - throttle_average: ${update_interval}
    voltage:
      name: Voltage
      id: v_sensor
      filters:
        - throttle_average: ${update_interval}
    power:
      name: Power
      id: w_sensor
      filters:
        - throttle_average: ${update_interval}
      on_value_range:
        - above: 4.0
          then:
            - light.turn_on: switch_led
        - below: 3.0
          then:
            - light.turn_off: switch_led
    energy:
      name: Energy
      id: wh_sensor
      unit_of_measurement: Wh
      device_class: energy
      state_class: total_increasing
      filters:
        - delta: 0.1

  - platform: total_daily_energy
    name: Total Daily Energy
    power_id: w_sensor
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh

  - platform: wifi_signal
    name: Wifi RSSI
    update_interval: 60s

  - platform: uptime
    id: uptime_sensor
    internal: True
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

  - platform: internal_temperature
    name: "ESP32 Internal Temp"
    id: esp32_temp

  - platform: template
    name: Power Factor
    device_class: power_factor
    id: power_factor
    lambda: |-
      if (id(v_sensor).state <= 0 || id(a_sensor).state <= 0) return 0;
      return id(w_sensor).state / id(v_sensor).state / id(a_sensor).state;


binary_sensor:
  - platform: gpio
    pin:
      number: GPIO00
      ignore_strapping_warning: true
    id: reset
    internal: true
    filters:
      - invert:
      - delayed_off: 10ms
    on_click:
      - max_length: 350ms # short press to toggle the relay
        then:
          switch.toggle: relay_1
      - min_length: 360ms # long press to cycle display info
        max_length: 3s
        then:
          - if:
              condition:
                binary_sensor.is_on: page
              then:
                binary_sensor.template.publish:
                  id: page
                  state: OFF
              else:
                binary_sensor.template.publish:
                  id: page
                  state: ON
  
  - platform: template # this is a fake sensor to tell the screen which info to show on display
    id: page
    trigger_on_initial_state: true
    internal: true
  
  - platform: template
    name: Load
    id: load_on
    lambda: |-
      if (isnan(id(w_sensor).state)) return {};
      return id(w_sensor).state > 4;

display:
  platform: tm1621
  id: tm1621_display
  cs_pin: GPIO25
  data_pin: GPIO14
  read_pin: GPIO26
  write_pin: GPIO27
  lambda: |-
    if (id(page).state) {
      it.display_voltage(true);
      it.display_kwh(false);
      it.printf(0, "%.1f", id(v_sensor).state);
      it.printf(1, "%.1f", id(a_sensor).state);
    } else {
      it.display_voltage(false);
      it.display_kwh(true);
      it.printf(0, "%.1f", id(wh_sensor).state);
      it.printf(1, "%.1f", id(w_sensor).state);
    }

output:
  - platform: ledc
    id: led
    pin:
      number: GPIO18
      inverted: True


switch:
  - platform: template
    name: Relay
    optimistic: true
    id: relay_1
    turn_off_action:
      - switch.turn_on: relay_off
    turn_on_action:
      - switch.turn_on: relay_on


  - platform: gpio
    restore_mode: ALWAYS_OFF
    internal: true
    id: relay_off
    pin: GPIO04
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_off # bi-stable relay so no need to keep on
      - light.turn_off: switch_led
    interlock: [relay_on]

  - platform: gpio
    restore_mode: RESTORE_DEFAULT_ON
    internal: true
    id: relay_on
    pin:
      number: GPIO02
      ignore_strapping_warning: true
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_on  # bi-stable relay so no need to keep on
      - light.turn_on: switch_led
    interlock: [relay_off]

  - platform: restart
    name: Restart


text_sensor:
  - platform: template
    name: Uptime
    id: uptime_human
    icon: mdi:clock-start

  - platform: wifi_info
    ip_address:
      name: IP
    ssid:
      name: SSID
    bssid:
      name: BSSID

light:
  - platform: monochromatic
    id: switch_led
    output: led
    internal: True

  - platform: status_led
    id: wifi_status_led
    internal: True
    pin:
      number: GPIO05
      inverted: True
      ignore_strapping_warning: true

interval:
  - interval: 30s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - light.turn_on: wifi_status_led
        else:
          - light.turn_off: wifi_status_led   

Is there a reason setting ‘restore_mode’ to ‘ALWAYS_ON’ wouldn’t work?

I would also expected this to work, yet didnt work as expected (power is restored and relay stays off)

Try how this alone behaves

  on_boot:
    priority: 600.0
    then:
      - delay: 2s
      - switch.turn_on: relay_on

And esphome logs usually give an idea what’s going on…