Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103026

Hard coded Entity in Custom Card doesnt work

$
0
0

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:

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>