Shreyas-R / lovelace-wallpanel-screensaver

Wall panel mode for your Home Assistant Lovelace dashboard with more focus on screensaver. Configurable extension which features a fullscreen kiosk mode, image and weather-clock screensaver, screen wake lock and the ability to hide side and top bar.
GNU General Public License v3.0
28 stars 0 forks source link

Use HA sensor data for temp display? #22

Open smartroad opened 2 years ago

smartroad commented 2 years ago

Hi! I was just wondering on the screen saver, is there anyway to have the temperature show the sensor I have in the room that it is in rather than the fetched outside temp?

Sorry if i have missed in the instructions!

Shreyas-R commented 2 years ago

You can use info template to achieve this.

Suppose you have a temperature sensor entity named temp_sensor under Home Assistant which provides temperature values under the state or any other attributes then you can use it in info_template parameter as follows:

states[temp_sensor].state

Or

states[temp_sensor].attributes.temperature

The following example uses states[temp_sensor].attributes.temperature to show the temperature fetched from local sensor.

wallpanel_screensaver:
  ...
  ...
  info_template: '
    <div id="wallpanel-screensaver-info-weather">
          <table>
            <tr>
                <th><img id="weather-temperature-icon" src="{{ filesParentPath }}/weather-icons/thermometer.svg"/></th>
                <th>{{ states[temp_sensor].attributes.temperature }}°&ensp;</th>
                <th><img id="weather-state-icon" src="{{ filesParentPath }}/weather-icons/{{ states[config.weather_entity].state }}-sun-{{ states["sun.sun"].state.replace("_", "-"); }}.svg"/></th>
                <th>{{ states[config.weather_entity].state.replace(/(^|\s)[A-Za-zÀ-ÖØ-öø-ÿ]/g, c => c.toUpperCase()) }}</th>
              </tr>
          </table>
      </div>
      <div id="wallpanel-screensaver-info-time">{{ (new Date()).toLocaleTimeString(undefined, {hour: "2-digit", minute:"2-digit", hour12: config.hour_12}) }}</div>
      <div id="wallpanel-screensaver-info-date">{{ (new Date()).toLocaleDateString(undefined, {weekday: "short", year: "numeric", month: "short", day: "numeric"}) }}</div>'
smartroad commented 2 years ago

Thanks for the reply! I can't seem to get it to work, copy and pasted your example, changing temp_sensor to the name of the sensor in my instance (listed as sensor.xxx_room_temperature) but I get an error saying: ReferenceError: sensor is not defined or ReferenceError: xxx_room_temperature is not defined if I drop the sensor. (xxx is a person's name so am masking it here)

Here is the listing in HA: image

Sorry for being dumb and unable to figure this out :(

marcolega commented 2 years ago

try to use "" like this: "sensor.xxx_room_temperature". It is worked for me

SimonWellsAus commented 2 years ago

I use the following and it works perfectly

{{ states["sensor name here"].state }}

smartroad commented 2 years ago

Thanks for the advice!! finally had time to look at it here is what worked for me:

{{ states["sensor.xxx_room_temperature"].state }}°