Combining Javascript and Jinja2 - possible?

I have these 2 ways to detect “normal updates” and “hacs updates” that I found online:

[[[
        const outdatedHacsEntities = Object.values(entities.update).filter(
          (entity) => entity.platform === 'hacs' && is_state(entity.entity_id, 'on')
        );
        return outdatedHacsEntities.length || '';
      ]]]

and

{% set totalUpdates = states.update | selectattr('state', 'eq', 'on') | list | length %}
      {{ totalUpdates > 0  }}

I would like to combine the 2 values together but am not sure how -if possible at all.

Thank you

found this that does the same for hacs as the javascript above:

        {{- integration_entities('hacs')
        | select('match', '^update\.')
        | expand
        | selectattr('state','eq', 'on')
        | list 
        | count
        -}}

won’t mark this answered as the answer required would be more broad than this individual example

it would only be possible if the custom card allowed it. I doubt any outside lovelace gen would allow this. Even then, lovelace_gen only works with jinja, however you can use it in combination with cards that use JS. This allows you to combine them, but not in the way you’re thinking. And it makes the code quite unreadable.

TLDR: No it’s not possible at the moment outside a very obscure and advanced custom integration.

1 Like