Yeah that is a solution that iāve applied to other buttonsā¦but it would be so nice to have this solution self contained within the button definition
Iād recommend to use button-card by RomRaider. With this, you can easily set what you want in the button itself. Seems easier to work with, but thatās a (your) personal choice.
EDIT: you could use different tap actions on button-card as well, something like āone tapā is on/off, ādouble tapā is toggle between high and low and so on.
The syntax for custom button card isnāt jinja, itās JS (javascript). Secondly, no matter what youāre doing (Jinja or JS), you cannot template entire fields. You can only template individual fields. Thirdly, data is not a valid option for a tap_action service_call, it needs to be named service_data.
Lastly, this may not work. It depends on how far custom button card lets you template into an object. Last I checked, templates only work in specific areas. Iām not sure if it allows it here, itās been a while since I set these up.
I know its an old post, but if you guys could help me with this one I would really appreciate
Can I use template for the name: itself?
I got a boolean that turns on when I arrive at work, but I would like to show as well the total time that I spent at work. For the time spent I work I created a sensor that combines all work locations in to one
- platform: history_stats
name: Time at Work # >>>>>>>>>>>>>>> Total at work per Today <<<<<<<<<<<<<<<<<
entity_id: person.robert
state: >
{% set a = states('sensor.time_at_a')| float %}
{% set d = states('sensor.time_at_d')| float %}
{% set r = states('sensor.time_at_r')| float %}
{% set f1 = states('sensor.time_at_f1')| float %}
{% set f2 = states('sensor.time_at_f2')| float %}
{% set f3 = states('sensor.time_at_f3')| float %}
{{(a + d + r + f1+f2+f3)}}
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
what would be the proper syntax to show the above? I am keep getting the [object Object] and I tried few different scenarios wit curly brackets and ā or "
show_name: true
show_icon: true
type: custom:button-card
styles:
card:
- font: 12px/20px Roboto
- background: radial-gradient(rgb(58,0,228,50%), rgb(0,0,0))
- box-shadow: 0px 0px 20px rgb(18,81,219,100%)
tap_action:
action: toggle
entity: input_boolean.nfc_flagstar
name: WORK #{{states(sensor.time_at_work)}} ā works in dev tools/template
icon: mdi:vacuum
show_state: false
color: rgb(255,0,0)
color_type: icon
aspect_ratio: 1/1
Custom button card does not use Jinja templating, it uses javascript templates which cannot be tested in Dev Tools. According to the cardās docs, the name is templatable.
The first part of your comment is Off Topic for this thread. In the future start your own thread
History Stats Issue
You cannot use templates in the state of a History Stats sensor. As shown in the docs, it only accepts a string or list of strings.
thank you for your input, I was not trying to hijack an old post and especially go off topic. My one and only goal was to show how I arrived at the stage that I am stuck on