custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.93k stars 233 forks source link

SetTimeout or SetInterval Support? #716

Open Aduviel opened 1 year ago

Aduviel commented 1 year ago

I have several datapoints I would like to show via a single custom_field.

Is some variation of the following example possible?

custom_fields:
    status: |
    [[[
      function test() {
        if (variables.idx > 2) {
          variables.idx = 0 
        } else { 
          variables.idx++ 
        }
      }
      setInterval(test, 7000);
      return `<div
        style="font-size: 14px; 
        font-weight: bold;
        color: black;
        ">${variables.arr[variables.idx]}</div>`
    ]]]

The button card using the status field displays without errors, but the variable is not incrementing every 7 seconds.

RomRider commented 1 year ago

You can inspire yourself from this comment https://github.com/custom-cards/button-card/issues/436#issuecomment-782891871