How to extract/show a Entities power "Attribute" as a card on Frontend?

Would appreciate assistance with working out how to extract an attribute from a Smart Power Plug and show its value as a card (or simular).

About: I have many Tuya Smart Plugs which includes power info but by default the info only shows as a “Attribute” to the Switch (On/Off).

Example Only: Playing around and In Developer/Template below shows the correct result i.e. 46w.

binary_sensor:
- platform: template
sensors:
tuya-sw01_current_consumption:
value_template: >-
{{ states. switch.kogan_smart_plug_06.attributes.current_consumption }}
unit_of_measurement: ‘W’

Question: How do I show the result in the Frontend as a card or the likes. I have 10 devices to do.

Thanks in advance.

  1. Please format pasted code correctly for the forum. It helps us help you.

  2. Binary sensors only have the states on and off. Power is not a binary_sensor, it is a sensor.

  3. Heed the warning box here: https://www.home-assistant.io/docs/configuration/templating/

  1. You should use the new format for new sensors. Try this:

configuration.yaml

template:
  - sensor:
      - name: "Kogan Plug 06 Power" # or whatever you want to call it
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement # only include this line if you want long term statistics
        state: "{{ state_attr('switch.kogan_smart_plug_06', 'current_consumption') }}"

      - name: "Kogan Plug 07 Power" # or whatever you want to call it
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement # only include this line if you want long term statistics
        state: "{{ state_attr('switch.kogan_smart_plug_07', 'current_consumption') }}"

      - name: etc...

You can then add these entities to any dashboard card. See the right hand column here. History graph or Entities cards would be good choices.

1 Like

Excellent. thank you for that and for answering so quickly. That is exactly what I was looking for.

I also appreciate that you took the time to also include:

  • the “State _Class” for long term stats as I was thinking about that but didn’t want to complicate my query with additional information.

  • and also noted how to use it i.e. History graph or Entities cards and included a link.

Apologies about my original “Pasted Format”. I just pasted what showed in Templates. I was none the wiser hence why I came here for assistance :slight_smile:

All sorted, thanks again for an A-Z answer. Nice work and much appreciated.

1 Like