Closed 532910 closed 7 months ago
Hi,
I don't know of any way to use a sensor to update a card. You should create a helper that keeps the value and gets updated using a service call. Then, use that helper to show the image in the card.
You can follow this steps:
input_text.random_image
.'%02d' % range(0, 20) | random
type: custom:media-source-image-card
image: |
media-source://media_source/local/{{ states('input_text.random_image') }}
entity_id: input_text.random_image (or other entity if you want to toggle state or anything)
Yep, I know, and it works for me:
type: custom:media-source-image-card
image: media-source://{{ states("sensor.photo") }}
sensor.photo template:
media_source/local/x/{{ '%02d' % range(1, 20) | random }}.jpeg
automation:
trigger:
- platform: time_pattern
seconds: /10
action:
- service: homeassistant.update_entity
target:
entity_id: sensor.photo
But this solution requires helper to work. I would be nice just to call service from an automation directly:
type: custom:media-source-image-card
id: photo
image: media-source://media_source/local/x/{{ '%02d' % range(1, 20) | random }}.jpeg
trigger:
- platform: time_pattern
seconds: /10
action:
- service: media-source-image-card.update
target:
id: photo
I'd rather not create a helper for some internal stuff.
Believe me, I HATE to have extra helpers too... but I think only integrations can have services, not custom cards.
Anyhow, a simple forced refresh would work for this, as the template would be re-evaluated. That way, the automation won't be needed either.
Let me give a try and I can include It.
I just published a new version (0.3.0) adding this feature and an example in the readme.
Can you give it a try to see if it works in your scenario and give me feedback?
Thanks!
Wow, it works like a charm!
I'd like to have a service to call from automation to update media-source-image-card: