Im trying to hard code an entity into a custom card but nothing seems to word, does anyone know how to fix this?
My custom card file…
class SecondTry extends HTMLElement {
// Whenever the state changes, a new `hass` object is set. Use this to
// update your content.
set hass(hass) {
// Initialize the content if it's not there yet.
if (!this.content) {
this.innerHTML = `
<ha-card header="Example-card">
<div class="card-content"></div>
</ha-card>
`;
this.content = this.querySelector('div');
}
const entityId = this.config.entity;
const state = hass.states[entityId];
const stateStr = state ? state.state : 'unavailable';
const myEntity = "sensor.average_mtemp";
this.content.innerHTML = `
The state of ${myEntity} is ${stateStr}!
<br><br>
<img src="http://via.placeholder.com/350x150">
`;
// The user supplied configuration. Throw an exception and Home Assistant
// will render an error card.
setConfig(config) {
if (!config.entity) {
throw new Error('You need to define an entity');
}
this.config = config;
}
This is what it shows which is what i put in the yaml card configuration, but i want it to show the “sensor.average_mtemp” which is what i tried to hardcode on the custom card: