ESPHOME logger.log format

I new to ESPHome, I wish to print the state of a device in the logger.log.
I cannot find the format to use for the state argument.
I try “format: “Hello World is %u”
args: [BuildInLED.state]”
Can anyone help please, this is my first with ESPHome and trying tracing help

Following is my code


platform: gpio
id: “BuildInLED”
number: D4
inverted: true


  • platform: binary
    output: “BuildInLED”
    name: "Build In LED "
    format: “Hello World is %u”
    args: [BuildInLED.state]

platform: gpio
number: D2
name: “PIR Sensor”
device_class: motion

Please post your code properly.

Have you read here? Logger Component — ESPHome

Thanks, I read the Logger Component - ESPHome.
the example is, I think for a digital number, I try the format in the example and it did not work.

Where can I find the instruction to format my code properly?

Here How to help us help you - or How to ask a good question

I think your args line would be

args: [ 'id(BuildInLED).state' ]

Just been playing with logging and the specifier (ie %u, %f, %s etc) has to match the data type of what you are printing.

When you compile, the compiler will stop and tell you if you have the wrong type.

Thank you, I also tried about every data type, without a success.
I can see the error message in the log

"src/main.cpp:213:56: error: request for member 'state' in 'BuildInLED', which is of pointer type 'esphome::gpio::GPIOBinaryOutput*' (maybe you meant to use '->' ?)
  213 |       ESP_LOGD("main", "Hello World is %d", BuildInLED.state);
      |                                                        ^~~~~"

The main issue is that I don’t know the data type of the device.state.

That’s a float, so use %f

Preformatted textUsing %f does not compile. It terminate with a fatal error.

- platform: binary
  output: "BuildInLED"
  name: "Build In LED "

      format: "Hello World the LED is %0f"
      args: [ 'id(BuildInLED).state']
      #format: The state of BuildInLED has changed

However when I compile using the commented format: The state……… changed, it compile. And when I turn on/off the LED from Home Assistant it give the state of my device before printing my message.

07:55:09][C][api:143]: Using noise encryption: NO
[07:55:21][D][api:102]: Accepted
[07:55:21][D][api.connection:827]: Home Assistant 2022.3.5 ( Connected successfully
[07:55:26][D][light:035]: 'Build In LED ’ Setting:
[07:55:26][D][light:046]: State: ON
[07:55:26][D][main:211]: The state of BuildInLED has changed
[07:55:31][D][light:035]: 'Build In LED ’ Setting:
[07:55:31][D][light:046]: State: OFF
[07:55:31][D][main:211]: The state of BuildInLED has changed