ESPhome interval automation doesnt work for restart

Hi,

I don’t quite understand why my node goes to boot loop (I think) on restart automation and why the public IP is not updated on start (like restart).

When I have the restart interval defined the ESP doesn’t start. Keeps booting.

When I have only the public IP, ESP works fine but the IP sensor is updated only after the timer.

Why restart seems to be updated on boot and the other interval sensor after set interval?

Is there a way to combine the two last interval sensors?
I couldn’t get it to accept two ‘then’ keywords in interval.

Intention of this node is to be installed on remote location (with public IP) and it will report temperature back to HA on another network. There is also web server running that will have a button to activate air conditioning.

button:
  - platform: restart
    name: "Restart"
    id: id_restart
     
http_request:
  useragent: offsite tempsensor
  timeout: 10s
  id: id_http_request

text_sensor:
  - platform: template
    name: "Public IP"
    id: id_public_ip
    icon: mdi:wan
    
interval:
  - interval: 24h
    then:
      button.press: id_restart
  # Check public IP
  - interval: 180min
    then:
      - http_request.get:
          url: http://wasab.is/json
          headers:
            Content-Type: application/json
          verify_ssl: false
          on_response:
            then:
              - lambda: |-
                  json::parse_json(id(id_http_request).get_string(),[](JsonObject root){id(id_public_ip).publish_state(root["ip"]);});

  - interval: 181min
    then:
      http_request.post:
        verify_ssl: false
        url: https://hooks.nabu.casa/....
        headers:
          Content-Type: application/json
        json:
          public_ip: !lambda |-
              return ((std::string) to_string(id(id_public_ip).state));

I realised all interval: components are triggered at boot. Then they are triggered on their specific interval.

Proved with this script:

interval:
  - interval: 5s
    then:
      - logger.log: "****** interval event 5s"
  - interval: 15s
    then:
      - logger.log: "****** interval event 10s"
  - interval: 1min
    then:
      - logger.log: "****** interval event 1min"

with this log at boot:

[D][wifi:386]: Starting scan...
[D][esp32.preferences:113]: Saving 1 preferences to flash...
[D][esp32.preferences:142]: Saving 1 preferences to flash: 1 cached, 0 written, 0 failed
[D][main:473]: ****** interval event 1min
[D][main:464]: ****** interval event 10s
[D][main:455]: ****** interval event 5s
[D][main:455]: ****** interval event 5s

So my conclusion is restarting can’t be done with intervals but I’ve done it with the time component:

time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 37
        hours: 12
        days_of_week: MON-SUN
        then:
           - logger.log: "***************** time event ***"
           - switch.toggle: device_restart

Hope this helps others.

1 Like

Good detective work!

I’ll add it to my conf straight away! :smiley: