ESP8266 - "interval" function problem, and change power mode on fly?

Hi,

I’m trying to use the onboard ESP led for states (the build in led status function does not work for me).

I want to flash the onboard led 3x in quick succession when Wifi is connected (will have other cases for different scenarios), eg flash 2x if wifi disconnected.

My problem is I can’t get anything to work, previously I was using Arduino interface and just wrote a function to check/do this, but I’m super stuck here.

example1:

interval:
  - interval: 20sec
    then: 
if:
    condition:
      wifi.connected:
    then:
      - logger.log: WiFi is connected Flashing ESPLED 3x fast!
      - switch.turn_on: onboard_led
      - delay: 200ms
      - switch.turn_off: onboard_led
    etc
etc

Question 2 - possible to change power on the fly?
I am powering the ESP off a parasite power from a 24v source. When I close “togglesw1” it shorts the power source with a relay. I have a vreg, diode, and large cap across the esp power in, however it sometimes reboots - Is there a way to shut off the wifi, do the toggle, then turn it back on?

example

- platform: gpio
    pin: D1
    inverted: True
    id: togglesw1
    restore_mode: ALWAYS_OFF
  - platform: template
    name: "togglesw1-D1"
    icon: "mdi:gate"
    turn_on_action:
  power_save_mode: full
    - delay: 100 ms 
    - switch.turn_on: togglesw1
    - delay: 100ms
    - switch.turn_off: togglesw1
    - delay: 100 ms 
  power_save_mode: full

Entire code:
code:

esphome:
  name: esptest1
  platform: ESP8266
  board: nodemcuv2

# picks best ssid
wifi:
  networks:
  - ssid: JCGG
    password: AFAFAFAFAF
  - ssid: GG
    password: AFAFAFAFAF
  - ssid: DEN
    password: AFAFAFAFAF
  - ssid: efc
    password: AFAFAFAFAF
  - ssid: efc_ext
    password: AFAFAFAFAF

## caused boot loop once
interval:
  - interval: 20sec
    then: 
  ## want to enter this condition from interval routine only if wifi is connected
  ## not sure how?? 
  #if:
#    condition:
#      wifi.connected:
    #then:
      - logger.log: WiFi is connected Flashing ESPLED 3x fast!
      - switch.turn_on: onboard_led
      - delay: 200ms
      - switch.turn_off: onboard_led
      - delay: 200ms
      - switch.turn_on: onboard_led
      - delay: 200ms
      - switch.turn_off: onboard_led
      - delay: 200ms
      - switch.turn_on: onboard_led
      - delay: 200ms
      - switch.turn_off: onboard_led

# Enable logging
logger:

# Enable Home Assistant API
api: 
  password: "Welcome$1"

ota:

# Example configuration entry
dallas:
  - pin: D2

## disable status led - doesn't have behaviour needed
## status_led:
##  pin: GPIO2

# Example configuration entry
light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO3
    num_leds: 4
    rgb_order: GRB
    name: "Heat #1"
  
      effects:
      # Use default parameters:
      - random:
      # Customize parameters
      - random:
          name: "My Slow Random Effect"
          transition_length: 30s
          update_interval: 30s
      - random:
          name: "My Fast Random Effect"
          transition_length: 4s
          update_interval: 5s
          
# Individual sensors
sensor:
  - platform: dallas
    ##address: 0xCA0000044AD76C28
    index: 0
    name: "18B20 tester#1 Temperature"
#    index: 1
#    name: "18B20 tester#2 Temperature"
  

switch:
  - platform: gpio
    pin: D4
    inverted: True
    id: onboard_led
    name: "onboard_led"
    icon: "mdi:restart"
    #restore_mode: ALWAYS_OFF
    
  - platform: gpio
    pin: D5
    inverted: True
    id: relay2
    name: "relay2"
    icon: "mdi:restart"
    restore_mode: ALWAYS_ON

    
  - platform: gpio
    pin: D1
    inverted: True
    id: togglesw1
    restore_mode: ALWAYS_OFF
  - platform: template
    name: "togglesw1-D1"
    icon: "mdi:gate"
    turn_on_action:
    ## can we disable wifi here before toggling switch ON ?
    ## power_save_mode: none
    - switch.turn_on: togglesw1
    - delay: 100ms
    - switch.turn_off: togglesw1


The reason nothing is working in example 1 above is because you are not indenting properly. Here’s a sample out of the online documentation. Number of spaces is important for indents.

on_...:
  then:
    - if:
        condition:
          lambda: 'return id(some_sensor).state < 30;'
        then:
          - logger.log: "The sensor value is below 30!"
          - light.turn_on: my_light
          - delay: 5s
        else:
          - logger.log: "The sensor value is above 30!"
    - light.turn_off: my_light

Sorry can’t answer your second question.