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

Formatting last_changed #2

Open
tonyp opened this issue Feb 4, 2019 · 5 comments
Open

Formatting last_changed #2

tonyp opened this issue Feb 4, 2019 · 5 comments

Comments

@tonyp
Copy link

tonyp commented Feb 4, 2019

It would be great to have the ability to format the secondary_info attributes (cutting of parts of the string etc.).

@MizterB
Copy link
Collaborator

MizterB commented Mar 6, 2019

This may be possible in the future. I have suggested that card-tools implement the ability for templates to reference functions that could execute arbitrary code. No commitments on when/if that will be possible, but it is being considered.

@GoNzCiD
Copy link

GoNzCiD commented Jul 8, 2019

I solve it with this:

card:
  entities:
    - entity: switch.myswitch
      secondary_info: '${ new Date(states[''switch.myswitch''].last_updated).toLocaleString(''es-ES'') }'
      type: 'custom:secondaryinfo-entity-row'
  show_header_toggle: false
  title: ⚙️ My Title
  type: 'custom:hui-entities-card'
type: 'custom:config-template-card'

@tyjtyj
Copy link

tyjtyj commented Sep 15, 2019

@GoNzCiD it dint work for me ... need some additional JS ?

      card:
        entities:
          - entity: input_boolean.vr_tracking_anyone
            secondary_info: '${ new Date(states[''input_boolean.vr_tracking_anyone''].last_updated).toLocaleString(''es-ES'') }'
            type: 'custom:secondaryinfo-entity-row'

@GoNzCiD
Copy link

GoNzCiD commented Oct 22, 2019

@GoNzCiD it dint work for me ... need some additional JS ?

      card:
        entities:
          - entity: input_boolean.vr_tracking_anyone
            secondary_info: '${ new Date(states[''input_boolean.vr_tracking_anyone''].last_updated).toLocaleString(''es-ES'') }'
            type: 'custom:secondaryinfo-entity-row'

I don't know if any other js are needed, I used all these for all the lovelace view I had at this moment:

  - type: module
    url: >-
      https://cdn.jsdelivr.net/gh/bramkragten/custom-ui@master/weather-card/weather-card.min.js
  - type: module
    url: /community_plugin/config-template-card/config-template-card.js
  - type: module
    url: /community_plugin/secondaryinfo-entity-row/secondaryinfo-entity-row.js
  - type: js
    url: /community_plugin/vertical-stack-in-card/vertical-stack-in-card.js
  - type: js
    url: /community_plugin/lovelace-markdown-mod/markdown-mod.js
  - type: js
    url: /community_plugin/lovelace-card-tools/card-tools.js
  - type: module
    url: /community_plugin/mini-graph-card/mini-graph-card-bundle.js

@Rabbit10
Copy link

Rabbit10 commented Nov 12, 2021

#18

bonjour,
cela date mais,
j'ai moi même rencontré ce problème, je l'ai contourné en créant une automatisation qui ce déclanche à chaque changement d'état de mon capteur d'ouverture (qui ce réinitialise a 0 minute 0 seconde à chaque redémarrage de HASS)
et utilisé l'attribut "last_triggered" de cette automatisation qui ne ce réinitialise pas, afin d'avoir le dernier changement d'état correct.
mais en l'utilisant tel quel cette attribut, je me retrouve dans le cas de @Mariusthvdb du sujet #18 en début de ce poste.

68958746-fbf3c080-07cc-11ea-9405-013448b8b93c

j'ai donc fait ce Template afin d'avoir un affichage qui correspond à mes attentes après un redémarrage de HASS.
Capture

type: grid
cards:

  • type: entities
    entities:
    • entity: binary_sensor.porte_d_entree
      type: custom:secondaryinfo-entity-row
      secondary_info: >-
      {% set automation_entity ='automation.detecteurouverture_porte_d_entree_change' %}
      {% set temps_ecoule = as_timestamp(now())-as_timestamp(state_attr(automation_entity,'last_triggered')) %}
      {% set jour_ecoule = (temps_ecoule/86400) | round(0 , "floor") %}
      {% set temps_ecoule_restant = (temps_ecoule-(jour_ecoule86400)) %}
      {% set heur_ecoule = (temps_ecoule_restant/3600) | round(0 , "floor") %}
      {% set temps_ecoule_restant = (temps_ecoule_restant-(heur_ecoule
      3600)) %}
      {% set min_ecoule = (temps_ecoule_restant/60) | round(0 , "floor") %} {% set temps_ecoule_restant = (temps_ecoule_restant-(min_ecoule*60)) %}
      {% set seconde_ecoule = (temps_ecoule_restant) | round(0 , "floor") %}
      Il y a {% if jour_ecoule != 0 %}{{jour_ecoule}} jr {% endif %}{% if heur_ecoule != 0 %}{{heur_ecoule}}h{% endif %}{% if min_ecoule != 0 %}{{min_ecoule}}min{% endif %}{% if seconde_ecoule != 0 %} et {{seconde_ecoule}}sec{% endif %}

c'esyt long pour un secondary_info, mais ça fonctionne.

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

No branches or pull requests

5 participants