How to display the status of a switch?

I have a switch whose status I want to be displayed in the UI (Card).

I’m able to get the status from the Developer tools > Template:

{{ states('switch.tira_led_cocina') }}

The above shows “on” or “off” depending on the switch state, but not sure how to display that on a given card.

Code on the ESP is:

switch:
  - platform: gpio 
    inverted: False
    pin: 2
    name: "Tira LED cocina"
    id: rele_led_cocina
    restore_mode: ALWAYS_ON

TIA

Use an Entity card

or a button card.

I already have an Entity Card to control my kitchen lightning (Luces)

image

I’d like to add a visual indication that another switch (relay) is on/off, like so:

image

Like this?

image

If so, you just need a sensor that reads the state and displays it on the entity card.

Exactly! But not sure how to implement that in the YAML. As far as I know, it’d be a Lamda that publishes the state using a template, but couldn’t make it work.

Not exactly. You just need a termplate sensor. Name it something like ‘kitchen_leds’ and then set it to the state of the light. When the light changes state the sensor states. Then in the frontend it just reads the sensor state and displays it.

I think they’re called helpers now? I’m really not sure. I wrote almost 99% of my HA config over 7 years ago and changed very very little. But looking at it its easily doable

Is this what you’re looking for?

EDIT: Once you make the sensor(helper) you just add it to your entity card. It should display the state.

1 Like

Got it working, thanks for your help!

image

1 Like