How to display a graph in a card

No problems here getting attributes from a switch in the templates tool.
{{ states.switch.playstation4.attributes }}
returns
{'icon': 'mdi:playstation', 'friendly_name': 'Playstation 4', 'assumed_state': False}
So it should work in the template sensor too.

@llingnau, maybe try:
{{ states.switch.pc_power_24.attributes.current_power_w }} and see if it works.

1 Like

That’s pretty cool. Thanks for the help @VDRainer!

Thanks all.
In my case I was trying to work out how to make a graph based on the current_power_w attribute of a smart outlet. I did it by adding the following to configuration.yaml:

# Sensors
sensor:
  # Weather prediction
  - platform: yr

  # Template to pull the power draw value from power outlet connected to Naim power amp
  - platform: template
    sensors:
      naim_amp_current_power_w:
        value_template: "{{ state_attr('switch.naim_amp','current_power_w') }}"
        unit_of_measurement: W
        device_class: power

sensor.naim_amp_current_power_w shows up as an entity now, which is easy to graph using the History Graph component.