tomvanswam / compass-card

A Lovelace card that shows a directional indicator on a compass for Home Assistant
MIT License
172 stars 19 forks source link

Dynamically change background image #893

Open ggonmar opened 3 months ago

ggonmar commented 3 months ago

I would like to be able to have a dynamic background that I can set based on the state of a sensor or some other element.

My intention is to use the card for showing the sun position in regards to my house (which picture I'd put in the compass card), and ideally I would have the image changing in order to show the shade moving with the sun position.

I tried unsuccessfully to apply it like such:

type: custom:compass-card
indicator_sensors:
  - sensor: sun.sun
    attribute: azimuth
    indicator:
      type: circle
    state_abbreviation:
      show: false
language: es
compass:
  north:
    offset: 110
    show: false
  circle:
    background_image: >
      {% set azimuth = state_attr('sun.sun', 'azimuth') | float %} {% if azimuth
      < 45 %}
        /local/images/home_sun/home1.png
      {% elif azimuth < 135 %}
        /local/images/home_sun/home2.png
      {% elif azimuth < 225 %}
        /local/images/home_sun/home3.png
      {% elif azimuth < 315 %}
        /local/images/home_sun/home4.png

This would be great to have! Thank you!

tomvanswam commented 2 months ago

Thanks for the feature request, I'll put it on my list.