Restart Button/Switch and logging

I’ve enabled both the Reset Button and Switch. I’m trying to send my own message to the ESPHOME log, but nothing is being written when I use either reset method. However, the Tare button does write to the log.

Are these logging commands reachable?

button:
  - platform: template
    id: weight_tare_set
    name: 'Tare'
    on_press:
      - lambda: id(weight_tare) = id(weight_no_tare).state;
      - logger.log: "Hello World Tare"

  - platform: restart
    id: scale_restart
    name: "Restart Button"
    on_press: 
      - logger.log: "Restart Button Hello World"

switch:
- platform: restart
  id: scale_switch
  name: "Restart Switch" 
  on_turn_on: 
    - logger.log: "Restart Switch Hello World"

Here is a code for Restart Button:

void RestartButton::press_action() {
  ESP_LOGI(TAG, "Restarting device...");
  // Let MQTT settle a bit
  delay(100);  // NOLINT
  App.safe_reboot();
}

IMHO You must see in log Restarting device..., but nothing more.

Add another switch to switch restart switch :wink:

  - platform: template
    id: restart2
    name: "Restart2"
    on_turn_on: 
      - logger.log: "Restart Switch Hello World"
      - delay: 100ms
      - switch.toggle: scale_switch

I have used the restart button in my standard yaml code … i thought successfully … though without the logger.log action.

I will try both on my ESP32-S3. my yaml code includes

logger:
  level: DEBUG

switch:
  - platform: restart
    id: scale_switch
    name: "Restart Switch" 
    on_turn_on: 
      - logger.log: "Restart Switch Hello World"

button:
  - platform: restart
    name: $devicename Restart
    on_press: 
      - logger.log: "Restart Button Hello World"

restart button

Pressing the Restart button in the View screen results in the “‘esp32d3-devkitc Restart’ pressed” log message (as I would expect) but NOT the desired “Restart Button Hello World” logger.log message.

Looking into the Button Component I see the first example exactly as we have it … but reading further down the example under on_press adds the indented line then:. Adding the "then: line and installing gives:

[14:52:54][D][time:050]: Synchronized time: 2025-04-04 14:52:54
[14:53:25][D][button:010]: 'esp32s3-devkitc Restart' Pressed.
[14:53:25][I][restart.button:012]: Restarting device...
[14:53:25][I][app:132]: Rebooting safely...
[14:53:25][D][esp32.preferences:114]: Saving 2 preferences to flash...

No change, and no logger.log output :frowning:

Restart switch

How about the Restart Switch, including the “then:” line … Clicking the “Restart Switch” to “On” results in

[14:56:07][D][sensor:093]: 'esp32s3-devkitc BH1750 Illuminance': Sending state 14.26181 lx with 1 decimals of accuracy
[14:56:23][D][switch:012]: 'Restart Switch' Turning ON.
[14:56:23][D][switch:055]: 'Restart Switch': Sending state OFF
[14:56:23][I][restart:016]: Restarting device...
[14:56:23][I][app:132]: Rebooting safely...
[14:56:23][D][esp32.preferences:114]: Saving 1 preferences to flash...

my conclusion

is that I am as puzzled as you. I use logger.log in other parts of my yaml code and they work fine there. I cannot see any reason for logger.log not working in the restart button or switch :frowning:

Lets try increasing the log level in case that provides extra information. Changing logger: level: to VERBOSE does give more info t o the log … but where has the reset button gone ?

[15:46:49][D][sensor:093]: 'esp32s3-devkitc AM2320 Humidity': Sending state 54.40000 % with 1 decimals of accuracy
[15:46:49][V][json:020]: Attempting to allocate 512 bytes for JSON serialization
[15:46:49][V][json:040]: Size after shrink 120 bytes
[15:46:49][V][mqtt:495]: Publish(topic='esp32s3-devkitc/sensor/esp32s3-devkitc_am2320_humidity/state' payload='54.4' retain=1 qos=0)
[15:46:49][W][component:237]: Component am2320.sensor took a long time for an operation (68 ms).
[15:46:50][W][component:238]: Components should block for at most 30 ms.
[15:46:55][V][esp-idf:000][httpd]: E (469485) httpd: httpd_accept_conn: error in accept (23)

[15:46:55][V][esp-idf:000][httpd]: W (469495) httpd: httpd_server: error accepting new connection

[15:47:09][V][bh1750.sensor:151]: L result: 44.516129 -> Calculated mode=2, mtreg=254
[15:47:10][D][bh1750.sensor:159]: 'esp32s3-devkitc BH1750 Illuminance': Got illuminance=50.7lx
[15:47:10][V][sensor:043]: 'esp32s3-devkitc BH1750 Illuminance': Received new state 50.708656
[15:47:10][D][sensor:093]: 'esp32s3-devkitc BH1750 Illuminance': Sending state 50.70866 lx with 1 decimals of accuracy
[15:47:10][V][json:020]: Attempting to allocate 512 bytes for JSON serialization
[15:47:10][V][json:040]: Size after shrink 124 bytes
[15:47:10][V][mqtt:495]: Publish(topic='esp32s3-devkitc/sensor/esp32s3-devkitc_bh1750_illuminance/state' payload='50.7' retain=1 qos=0)
[15:47:15][V][sensor:043]: 'esp32s3-devkitc Wakeup cause': Received new state 0.000000
[15:47:15][D][sensor:093]: 'esp32s3-devkitc Wakeup cause': Sending state 0.00000  with 0 decimals of accuracy
[15:47:15][D][main:290]: >>>>>> WOKEN UP logger   esp_sleep_get_wakeup_cause()=0, wakeup_cause=1070200340, num_wake_cycles=0 
[15:47:15][D][testing:291]: >>>>>> WOKEN UP LOGD   esp_sleep_get_wakeup_cause()=0, wakeup_cause=0, num_wake_cycles=0
[15:47:15][V][json:020]: Attempting to allocate 512 bytes for JSON serialization
[15:47:15][V][json:040]: Size after shrink 112 bytes
[15:47:15][V][mqtt:495]: Publish(topic='esp32s3-devkitc/sensor/esp32s3-devkitc_wakeup_cause/state' payload='0' retain=1 qos=0)
[15:47:32][V][esp-idf:000][httpd]: E (506046) httpd: httpd_accept_conn: error in accept (23)

[15:47:32][V][esp-idf:000][httpd]: W (506054) httpd: httpd_server: error accepting new connection

[15:47:42][D][pulse_counter:186]: 'esp32s3-devkitc Rain Gauge': Retrieved counter: 0.00 pulses/min
[15:47:42][V][sensor:043]: 'esp32s3-devkitc Rain Gauge': Received new state 0.000000
[15:47:42][D][sensor:093]: 'esp32s3-devkitc Rain Gauge': Sending state 0.00000 pulses/min with 2 decimals of accuracy
[15:47:42][V][json:020]: Attempting to allocate 512 bytes for JSON serialization
[15:47:42][V][json:040]: Size after shrink 124 bytes

The two times i pressed the Reset Button appear to be replaced by httpd errors

[15:46:55][V][esp-idf:000][httpd]: E (469485) httpd: httpd_accept_conn: error in accept (23)

[15:46:55][V][esp-idf:000][httpd]: W (469495) httpd: httpd_server: error accepting new connection

Now, that is strange !

The Restart Switch appears to behave as before

[15:54:44][D][switch:012]: 'Restart Switch' Turning ON.
[15:54:44][D][switch:055]: 'Restart Switch': Sending state OFF
[15:54:44][D][main:788]: Switch Turned Off!
[15:54:44][I][restart:016]: Restarting device...
[15:54:44][I][app:132]: Rebooting safely...

and oddly now the restart Button is also behaving as before.