trentjw
(Trenton J Wilson)
January 9, 2020, 12:07am
1
Trying to get the name to change on a button card based on the status of the switch it is controlling.
for example when the switch in is on, it would display heat is enabled, when switched off it would display A/C is enabled.
I already built a sensor that shows those messages in its state and works like it should just need to know how to use that sensors state in the name part of the button thanks
trentjw
(Trenton J Wilson)
January 9, 2020, 1:57am
3
well that did not work
entity: switch.tp_link_smart_switch_e720
hold_action:
action: more-info
icon: 'mdi:power'
name: >-
[[[ if (switch.tp_link_smart_switch_e720.state on) return "Heat is Enabled";
else return "A/C is Enabled"]]]
show_icon: true
show_name: true
tap_action:
action: toggle
type: custom:button-card
callifo
(Callifo)
January 9, 2020, 2:02am
4
You have no condition between the object and status in the ‘if’ statement. Make sure you also copy the way its written out, I’ve had a bit of an issue getting stuff to work using that, and it will not generate any errors in the log when you do get it wrong.
Paste the whole thing into the developer template page and see what it is evaluated to.
trentjw
(Trenton J Wilson)
January 9, 2020, 2:04am
5
this is the template that was on the link you posted
name: '[[[ if (entity.state > 42) return "Above 42"; else return "Below 42" ]]]'
name: >
[[[
if (entity.state > 42)
return "Above 42;
else
return "Below 42;
]]]
tried both ways and it saves to what I posted with the >- in the line
trentjw
(Trenton J Wilson)
January 9, 2020, 2:10am
6
this is from the dev template
entity: switch.tp_link_smart_switch_e720
hold_action:
action: more-info
icon: 'mdi:power'
name: [[[ if (switch.tp_link_smart_switch_e720.state on) return "Heat is Enabled"; else return "A/C is Enabled"]]]
show_icon: true
show_name: true
tap_action:
action: toggle
type: entity-button
I tried inserting a = sign between .state and on still did not work same result with is
trentjw
(Trenton J Wilson)
January 9, 2020, 2:20am
7
this is what I got to work in my sensor and it works fine
{% if is_state('switch.tp_link_smart_switch_e720', 'on') %}
Heat is Enabled
{% else %}
A/C is Enabled
{% endif %}!"
but won’t work in the button entity name:
callifo
(Callifo)
January 9, 2020, 3:31am
8
Yeah, if its not being processed in the development template page, its not working properly. I’ve found the javascript side of this to be temperamental. This not work?
entity: switch.tp_link_smart_switch_e720
hold_action:
action: more-info
icon: 'mdi:power'
name: '[[[ if (switch.tp_link_smart_switch_e720.state == 'on') return "Heat is Enabled"; else return "A/C is Enabled" ]]]'
show_icon: true
show_name: true
tap_action:
action: toggle
type: entity-button
Yeah template sensor above is Jinja, so it won’t work in the name template as that is Javascript.
trentjw
(Trenton J Wilson)
January 9, 2020, 3:44am
9
nope tried in both dev template and on the button entitiy even with the == still does not work
trentjw
(Trenton J Wilson)
January 9, 2020, 3:52am
10
replace the entity with one of yours and try it out in your dev template let me know the results
callifo
(Callifo)
January 9, 2020, 3:56am
11
I’ll get a copy of my config tonight, as I have done this previously and it worked fine. There must be something that’s not quite right.
callifo
(Callifo)
January 9, 2020, 8:19am
12
Looks like i havent used it for name, it’s label,
- type: "custom:button-card"
template: timer_status
entity: timer.alarm1_repeat
show_state: false
show_label: true
label: >
[[[
if (entity.state == 'idle') return "idle";
return states['sensor.timer_remaining_hms_alarm_1'].state;
]]]
One with if, elif and then else,
label: >
[[[
if (entity.state == 0) return "Today";
else if (entity.state == 1) return "Tomorrow";
else return "in "+entity.state+" days";
]]]