I want to show the history of current_temperature for the past couple days using either history graph card or custom:mini-graph-card, how can I access that attribute in the card?
I believe the difference between an entity attribute and a sensor (entity state) is that Home Assistant’s SQL database (History) does not keep the history of an attribute, but it keeps the state. So when you make a sensor from an attribute, it will cause the database to keeps its historic data.
Think of it this way, the developer of the integration thought it was an unnecessary waste of resources or cost to keep that data historically. If they thought it was essential to keep that data history, they would have made it a sensor instead of an attribute.
In your case, you would normally want to see a temperature history. I always add
secondary_info: last-updated
to all the sensors I view in the Lovelace so that I can see when they were updated. You might find that your thermostat current temperature is not producing a humanly sensible historic data.
You are trying to name an entity to sensor.media_player.frametv_title which can’t be done.
And I believe you have indentation issues also.
This is probably correct:
sensor:
- platform: template
sensors:
frametv_title:
friendly_name: FrameTV Media Title
entity_id:
- media_player.frametv
value_template: "{{ state_attr('media_player.frametv', 'media_title' }}"
Thanks for your quick help! I really appreciate it.
With your config I am getting the following error:
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensors']['frametv_title']['value_template']. Got "{{ state_attr('media_player.frametv', 'media_title' }}". (See ?, line ?).
Mind taking another look?
EDIT: I guess the “)” was missing. Thanks again!
Alright, I’ve made use of the latest yaml and inspecting the sensor through Developer Tools → State it tells me that state = unknown. It’s been more than 24h since I added the stanza, and I’ve also restarted HA repeatedly.
Why might this not work? How should I diagnose the issue?
- platform: template
sensors:
thermostat_fan:
friendly_name: Thermostat fan
value_template: "{{ state_attr('climate.thermostat.attributes.fan', 'off') }}"
outdoors_temperature:
friendly_name: Outdoors temperature
value_template: "{{weather.thermostat.temperature}}"