There’s no need to install another custom card for that.
What do you mean with showing the light color? The value or the color itself?
Sorry I meant i’d like the icon color of a custom button card to be the color of another light that it doesnt activate. So if it just turned a light on and off I could have color: auto and it would show red when the light is red, but this button controls a script that ends up with the light changing color, and I want to be able to use that color as the button’s icon color.
This are the data of my Hue Iris:
min_mireds: 153
max_mireds: 500
effect_list:
- colorloop
- random
supported_color_modes:
- color_temp
- hs
color_mode: hs
brightness: 89
hs_color:
- 38.667
- 52.941
rgb_color:
- 255
- 207
- 120
xy_color:
- 0.457
- 0.41
effect: none
friendly_name: Hue Iris
supported_features: 63
With
icon:
- color: |
[[[
return 'rgb(' + entity.attributes.rgb_color)'
]]]
I am able to call the rgb color of the light.
So when your tap action turns on another light via script, you should ne able to use the current light color.
Can I use a template for name:
or label:
such that it extracts the the remain_time
attribute from a sensor called sensor.washer
? This is a different sensor than I am using for entity:
Take a look here in the documentation of button-card
. These are the fields you can use templates:
Thanks. I had looked at that section and wasn’t really able to make sense of what I needed to do. Then I saw an example that clicked and got it working using this:
[[[ return states["sensor.washer"].attributes.remain_time ]]]
Thanks
thanks for the quick and easy answer
I’m quite new to this - is there a way to use a previous entity variable in a custom field?
e.g.
type: custom:button-card
entity: sensor.synstor_drive_1_temperature
hold_action:
action: more-info
aspect_ratio: 1/1
custom_fields:
graph:
card:
type: sensor
entity: sensor.synstor_drive_1_temperature
graph: line
style: |
ha-card {
box-shadow: none;
}
styles:
custom_fields:
graph:
- filter: opacity(50%)
- overflow: unset
card:
- overflow: unset
grid:
- grid-template-areas: '"i" "n" "graph"'
- grid-template-columns: 1fr
- grid-template-rows: 1fr min-content min-content
Is there a way to use the parent entity (sensor.synstor_drive_1_temperature) as the entity in the custom field instead of hard coding it? I’ve tried a few formats but can’t seem to get it recognised.
custom_fields:
graph:
card:
type: sensor
entity: "[[[ return entity.entity_id ]]]"
does the trick.
When I put my sensor, entity: sensor.rpi_uptime I get card displaying either “running” or the days, hours. How do I get the card to just display the correct hours?
Can;t see the wood for the treees, maybe I;ve been staring at this for too long. Can someone hint me why this won;t work?
stat: |
[[[
var staticon = 'red'
if (states['[[entity_nasdrivestate]]'].state == 'Normal') {
staticon = 'lime';
}
return `<ha-icon
icon="mdi:power-standby"
style="width: 16px; height: 16px; color: $(staticon);">
</ha-icon> <span>Status: <span style="color: white;">${states['[[entity_nasdrivestate]]'].state}</span></span>`
]]]
The state fills out correctly but the icon will not change colour on that state,
rpi_uptime:
friendly_name: RPi Uptime
value_template: >
{% set up_time = as_timestamp(now()) - as_timestamp(states('sensor.last_boot')) %}
{% set minutes = (up_time // 60) | int %}
{% set hours = (minutes // 60) %}
{% set days = (hours // 24) %}
{% set weeks = (days // 7) %}
{% set minutes = (minutes % 60) %}
{% set hours = (hours % 24) %}
{% set days = (days % 7) %}
{% macro phrase(value, name) %}
{%- set value = value %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{% set text = [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min') ] | select('!=','') | list | join(', ') %}
{% set last_comma = text.rfind(',') %}
{% if last_comma != -1 %}
{% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
{% endif %}
This is my sensor code. It works sometimes and other times the card displays running instead of the uptime.
Any ideas?
Does it show „running“ when uptime is under 1 minute?
Anyway, you might have a look at https://community.home-assistant.io/t/convert-seconds-to-days-hours-minutes/23152/22?u=pedolsky
Put the whole style definition in the variable (or use text-color-sensor
instead):
custom_fields:
stat: |
[[[
var nas = states['[[entity_nasdrivestate]]'].state;
var staticon = 'width: 16px; height: 16px; color: red;'
if (nas == 'normal') {
staticon = 'width: 16px; height: 16px; color: lime;';
}
return `<ha-icon
icon="mdi:power-standby"
style="${staticon}">
</ha-icon>Status: <span style="color: white;">${nas}</span>`
]]]
(added second variable because it’s easier).
———
Edit: cleaned <span>
It does not care how long I’m running. I have seen “running” while up several weeks. I’ll try the code referenced in your reply later and see if it works for me.
Any error in my code that is causing this? Trying to understand the code and figure out where the word running comes from. I would like to get an understanding of what I am doing wrong before I try something different.
Hello
I noticed that hold_action works kind of not reliable. I’m not able to define a pattern when it fails, but it’s pretty hard to execute an action using hold. Sometimes it works at first try, a few secs later I’m not able to succeed at all.
Not an issue of operating system since hold here works as expected (iOS14 and 15: iPhone X).
In HA app it seems like it’s too sensitive on finger movement during holding which cancels the hold feature. But it’s my rough guess.
Must not be caused by button card itself. Maybe browser-mod issue or whole iOS app?
Anyone else experienced this behavior? Is there any workaround on this?
I noticed the same, annoying. My „workaround“ is to use double_tap_action
if possible.
Can’t see this behaviour on Android, sorry (Android9, 10 or 11). And on Windows’/Linux either. Maybe something Apple related.
On Android you get a small circle and that is kind of “locked-in”, I can even move that circle around without loosing the hold action.
I agree here. In fact I changed all taps to hold because I found tap too sensitive and it would fire when scrolling if I touched the button. Tap does have quirks too but seems to work fine on Android where we are most of the time.