Dynamic entity based on time

Hi !

I have an integration wich give me the cost of a kWh electricity.
It provides me 2 entities :

  • ‘sensor.tarif_tempo_heures_creuses_ttc’ wich is the price between 10pm and 6am
  • ‘sensor.tarif_tempo_heures_pleines_ttc’ wich is the price between 6am and 10pm

In my dashboard, I would like to add a card wich displays the current price (so, depending of actual time).

I tried to use Mushroom Template Card with that following yaml code but it gives me unknown state…

type: custom:mushroom-template-card
entity: >
  {{ 'sensor.tarif_tempo_heures_creuses_ttc' if (now().hour >= 22 or now().hour < 6) else 'sensor.tarif_tempo_heures_pleines_ttc' }}
primary: Tarif actuel
secondary: >
  {{ states(entity) }} €
icon: mdi:currency-eur

Any idea on how to to that ?