luixal / lovelace-media-source-image-card

A Lovelace custom card for showing images stored in Media Source
GNU General Public License v3.0
21 stars 0 forks source link

Refresh picture #5

Closed mihaimdinca closed 9 months ago

mihaimdinca commented 9 months ago

I aim to use the card to view pictures stored in a folder. This is possible because the card supports templating. I use a input number to change the picture. The problem is that even though the picture address string changes in the desired way, the image itself does not refresh. Please add an option to refresh when image address/ location is changed.

BrendanxP commented 9 months ago

I ran into the same issue. Moreover, the card itself is quite restrictive and also does not want to play very nicely with some features from card mod. Maybe as a feature request, being able to get the url to the file with access token as part of a template sensor would likely solve many possible issues at once. I am not entirely sure if something like that is easily possible, but it would make for an awesome feature.

luixal commented 9 months ago

I aim to use the card to view pictures stored in a folder. This is possible because the card supports templating. I use a input number to change the picture. The problem is that even though the picture address string changes in the desired way, the image itself does not refresh. Please add an option to refresh when image address/ location is changed.

If I remeber rigth, I tried that same scenario when adding the code to support templating.

Can you share your card config?

Thanks!

luixal commented 9 months ago

I ran into the same issue. Moreover, the card itself is quite restrictive and also does not want to play very nicely with some features from card mod. Maybe as a feature request, being able to get the url to the file with access token as part of a template sensor would likely solve many possible issues at once. I am not entirely sure if something like that is easily possible, but it would make for an awesome feature.

Please, open another issue with the problems you found when using card mod with this cards and I'll try to solve them.

About the feature request, that can be done but I think it won't make sense to have a card just to set a sensor. That looks more like an integration but, as the token is in the browser, I'm not sure that can be easily done.

luixal commented 9 months ago

This bug has been fixed in version 0.2.1.

Just published.

mihaimdinca commented 8 months ago

I aim to use the card to view pictures stored in a folder. This is possible because the card supports templating. I use a input number to change the picture. The problem is that even though the picture address string changes in the desired way, the image itself does not refresh. Please add an option to refresh when image address/ location is changed.

If I remeber rigth, I tried that same scenario when adding the code to support templating.

Can you share your card config?

Thanks!

type: custom:media-source-image-card image: >- media-source://media_source/local/Doorbell/motion/{{(state_attr("sensor.db_motion_file_list","file_list")[int(states('input_number.doorbell_picture_number'))])[28:]}} entity_id: input_number.doorbell_picture_number Still not refreshing for me in version 0.2.3

luixal commented 8 months ago

Totally true. When watching for entities to refresh the card on (so it's not refereshed too much) I only thought about one entity being in the template and yours has two.

It may be solved in 0.2.4, but I couldn't test it, can you please try it and give me some feedback?

Thanks!

PS: Will be published in a while.

mihaimdinca commented 8 months ago

Sure. As soon as it is published, I will update and I will give it a try.

luixal commented 8 months ago

I published it yesterday, HACS should let you update it.

mihaimdinca commented 8 months ago

Tested it. Works great! Thank you very much for your great work!

BrendanxP commented 7 months ago

Apologies for getting back only so much later. I am thrilled you got it to work for yourself @luixal and for @mihaimdinca. However, on my end I cannot get it to work, but it might be from something I am doing wrong.

My goal is to have four pictures belonging to the same item, so for example, I would have 10 different items, all with a front, back, left, and right image. That's why I have four cards in a stack, and I generate random numbers using an input helper rather than using random on each card individually. Nevertheless, either using the input helper or using {{random}} in the card itself, I cannot get the card to update over time. I am currently on version 3.0 from HACS, I reloaded after upgrading and I refreshed with cleaning cookies. None of the cards refresh, unless I manually hit refresh or click the first card that triggers a complete lovelace browser mod refresh on all HA dashboards.

type: horizontal-stack
cards:
  - type: custom:media-source-image-card
    image: >-
      media-source://media_source/local/test{{ states('sensor.random_pokemon') }}.png
    entity_id: sensor.random_pokemon
    forced_refresh_interval: 10
    tap_action:
      action: call-service
      service: browser_mod.refresh
      data: {}
  - type: custom:media-source-image-card
    image: >-
      media-source://media_source/local/test{{ states('sensor.random_pokemon') }}.png
    entity_id: sensor.random_pokemon
    forced_refresh_interval: 10
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: script.play_sound_based_on_number
        data:
          browser_id: THIS
          number: '[[[ return states[''sensor.random_pokemon''].state; ]]]'
  - type: custom:media-source-image-card
    image: >-
      media-source://media_source/local/test{{ states('sensor.random_pokemon') }}.png
    entity_id: sensor.random_pokemon
    tap_action:
      action: none
  - type: custom:media-source-image-card
    image: >-
      media-source://media_source/local/test{{ '%01d' % range(0, 9) | random }}.png
    entity_id: sensor.random_pokemon
    forced_refresh_interval: 5
    tap_action:
      action: none
mihaimdinca commented 7 months ago

Have you checked if the templates return a valid path to a file?

luixal commented 7 months ago

Same I was about to say, please, check your templates resolve in a right way.

BrendanxP commented 7 months ago

Thanks for getting back and sorry for not specifying this clearly in the first post. But the quick answer to your question is yes.

The sensor generating the random number does change. I am fully sure as I also have a card that shows the state of the sensor as text, and I can check it in the entities tab. The next questions is do these paths actually resolve. Well yes, the only 10 options are tesy0.png upto test9.png. When I first load or manually refresh the page I do see the correct picture. I never not see a picture, it always resolves.

The problem at my end is simply that the picture never updates. I can see by the text of the other card that the sensor changed. If I manually refresh I can see the picture change accordingly. However, when I just wait it does not change, and I just see the same picture continuously. Tried it on the mobile app as well as on Edge (Chromium).

BrendanxP commented 7 months ago

It is fixed! I updated Home Assistant with an incremental update (I was already running the latest version), but now the pictures refresh! I am very confused about why and how this made it work, as I already tried a reboot after updating the card. It also did not work on both my phone and my laptop (Windows 11, Edge), and after updating HA it works on both.