Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Refresh SVG on animation/time/state/... #249

Open
stinobook opened this issue Apr 7, 2024 · 7 comments
Open

Feature: Refresh SVG on animation/time/state/... #249

stinobook opened this issue Apr 7, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@stinobook
Copy link

The Problem To Be Solved

usersvg images are loaded on card load, not on image load.

Additional background:

trying to implement a camera(image stream, not camera stream) view inside the card.

A concise description of your preferred solution. Things to address include:

I have written a derived entity so that my 'state' always updates every few seconds.
It switches between 2 states, and i have 2 images 'coupled' to it.

(Optional): Suggested Solution

how i see it now the images are 'preloaded' by the card as soon as the card is loaded, but if we can just load the image when it is requested instead of on card load this would make it update each time and allow us to insert a stream inside the card.

my tool:

                - type: usersvg
                  position:
                    cx: 50
                    cy: 55
                    height: 35
                    width: 50
                  style: 'images'
                  entity_index: 12
                  derived_entity:
                    input : '[[[ return state ]]]'
                    state: >
                      [[[
                        if (typeof(entity) === 'undefined') return;
                        if (typeof(state) === 'undefined') return;
                        if (state === 'undefined') return;
                        var sec = state.slice(-1);
                        if (sec % 2 == 0) {
                            return ('even');
                        } else {
                            return ('uneven');
                        }
                  images:
                    - default: /api/image_proxy/image.----
                    - even: /api/image_proxy/image.----
                    - uneven: /api/image_proxy/image.----
                  animations:
                    - state: 'even'
                      image: even
                    - state: 'uneven'
                      image: uneven`


@stinobook stinobook added the enhancement New feature or request label Apr 7, 2024
@kkggaa45
Copy link

Hi, try this example (this is how I output the video stream from the camera and album covers from the media player)

            ####################################################
                  - type: usersvg
                    position:
                      cx: 50
                      cy: 38
                      height: 73
                      width: 97
                    clip_path:
                        position:
                          cx: 50
                          cy: 50      
                          height: 73  
                          width: 97
                          radius:    
                            top_left: 1.2
                            top_right: 1.2
                            bottom_right: 1.2
                            bottom_left: 1.2
                    entity_index: 0
                    style: 'images'
                    images: 
                      - default: >
                          [[[
                            {
                              return (entity_config?.entity_picture ||
                                     entity.attributes?.entity_picture || 'none');
                            }
                          ]]]
            ####################################################

@stinobook
Copy link
Author

Does that update for you without refreshing the page? it just loads a static image which was also my issue.

@kkggaa45
Copy link

kkggaa45 commented Feb 3, 2025

Example of video stream output from a camera

  - type: 'custom:swiss-army-knife-card'
    entities:
        - entity: camera.cam051
    layout:
        aspectratio: 1/.58
        toolsets:
          - toolset: video
            position:
              cx: 50
              cy: 50
            tools:
        ####################################################
              - type: rectex
                entity_index: 0
                position:
                  cx: 50
                  cy: 29
                  width: 99
                  height: 57
                  radius:
                    top_left: 1.5
                    top_right: 1.5
                    bottom_right: 1.5
                    bottom_left: 1.5
                styles:
                    rectex:
                        stroke-width: 0.7em       # width of stroke. 0 = no stroke.
                        stroke: '#909090'
                        fill: '#363636'
    
        ####################################################
              - type: usersvg
                position:
                  cx: 50
                  cy: 29
                  height: 55
                  width: 97
                clip_path:
                    position:
                      cx: 50
                      cy: 50      
                      height: 55  
                      width: 97
                      radius:    
                        top_left: 1.3
                        top_right: 1.3
                        bottom_right: 1.3
                        bottom_left: 1.3
                entity_index: 0
                style: 'images'
                images: 
                  - default: >
                      [[[
                        {
                          return (entity_config?.entity_picture ||
                                 entity.attributes?.entity_picture || 'none');
                        }
                      ]]]
        ####################################################

@stinobook
Copy link
Author

Yes I got it working from your previous comment but that would give me a static image on the SAK card instead of a live view of the camera. Is it the same for you or do you have in fact a live updating feed ?

@kkggaa45
Copy link

kkggaa45 commented Feb 3, 2025

something like this
https://youtube.com/shorts/HemeLBO-lEI?feature=share

@stinobook
Copy link
Author

@kkggaa45
Copy link

kkggaa45 commented Feb 3, 2025

Do you use "filter:" in "styles:"? If so, comment out the lines with "filter:".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants