How do I log a State

Hi I have this setup as a switch

switch:
  - platform: template
    name: "Pow Access 1"
    optimistic: true
    id: acc1
    turn_on_action:
    - switch.turn_on: relay
    turn_off_action:
    - script.execute: sc_relayoff

How can I log the state of this switch so I can see it in the Log Screen after its been uploaded.

Regards Dave

Do you mean the Logbook screen?

It logs automatically on any change of state.

Thanks for taking the trouble to reply, its in the screen that you get when you select LOGS from ESPhome UI, it then connects to the device.

The screen shows the output turning on & off as per screen shot. But I am trying to use the state of this output in a script and not sure how read the state.in a “If Statement”

I assume I have to use the id? as

switch.is_on: sonoff_pow_access_1

trying to use the HA names does not work

But not sure if that is just a label or does it also hold the state of the switch?

POW screen

Found out how, post for anyone trying to do the same

    - logger.log:
        level: DEBUG
        format: 'The state of acc1 is %d'
        args: ['id(acc1).state']

But why do you want it in the log?

I was trying to debug a script, and needed to know the state.

Is there a better way?

Regards, Dave