Help with advanced switch

Yes, you can.

esphome:
  on_boot:
    priority: 600
    then:
      - lambda: |-
          id(pulse_relay_1).publish_state(id(powerstatus).state);

You could also change the binary_sensor to use the same code, if you want.

binary_sensor:
  - platform: gpio
    id: powerstatus
    pin:
      number: 14
      mode: INPUT_PULLUP
      inverted: True
    name: "Power Status"
    on_state:
      then:
        - lambda: |-
            id(pulse_relay_1).publish_state(id(powerstatus).state);

Or create a script they both call.

esphome:
  on_boot:
    priority: 600
    then:
      - script.execute: set_heater_switch

binary_sensor:
  - platform: gpio
    id: powerstatus
    pin:
      number: 14
      mode: INPUT_PULLUP
      inverted: True
    name: "Power Status"
    on_state:
      then:
        - script.execute: set_heater_switch          

script:
  - id: set_heater_switch
    mode: single
    then:
      - lambda: |-
          id(pulse_relay_1).publish_state(id(powerstatus).state);

Dang, you’re good at this aye!

1 Like