Button Card. States object access in template not up to date

Hello all. I have a strange behaviour when I try to template a custom button card.
I want to display a button for a shelly light switch (state on/off) but on a custom field, I want to display the shelly power consumption (same device, other entity).

On my template, I declared a variable with the name of the power entity like that :

button_card_templates:
  btn_shelly:
    variables:
      power_entity: 'Nothing'
    custom_fields:
      energy: |
        [[[
          console.log("variables.power_entity",variables?.power_entity);
          return `<span>${states[variables.power_entity]?.state}W</span>`;
        ]]]

and my card :

- type: custom:button-card
  entity: light.shelly_garage
  template: btn_shelly
  icon: mdi:home-floor-g
  variables:
    power_entity: 'sensor.shelly_garage_power'

but the custom field isn’t refrehsing properly. When I turn on, I don’t get the power state (I get 0). When I turn off, I am actually getting the power consumption (previous state …).

On and Off :
image

And what is really strange, if I name in comment, the target entity, after the return, the refresh is working (for the entity named, not the other) !

      energy: |
        [[[
          console.log("variables.power_entity",variables?.power_entity);
          return `<span>${states[variables.power_entity]?.state}W</span>`;
          // console.log(states["sensor.shelly_salleamanger_power"]);
        ]]]

Any idea ?
it seems that js template doesn’t support variable for states collection