Is there a way to add code in a card? Even something as simple as add an integer:
entities:
- input_number.day_rate + 2
Is there a way to add code in a card? Even something as simple as add an integer:
entities:
You can use templates in some cards. In general, keep logic and computations in the back end and just use the cards for display.
For this one, set up a template sensor helper with a state template of:
{{ states('input_number.day_rate')|float + 2 }}
and display that sensor in the card.
This was only an example.
Sometimes it is much easier to make calculations in a card.
Additionally, sometimes I would like to show content depending on some conditions, a la:
if x>y then input_number.day_rate
else input_number.night_rate
Look to the custom cards like the ones listed in HACS from github. Very few if any of the core cards use templates as HA has decided the path Troon suggested is the preferred way to go. (Rather than duplicating code for both the back end and the frontend in core.)
Note that a proper terminology is “use a template in a card”.
Calculations, conditions, loops - are only available inside a template.
Examples of custom cards supporting templates: template-entity-row, config-template-card, card-templater.
Choice is simple: