This looks like it could be a nice way to have my current AdGuard pause functionality in a button card, I was not aware of this nesting.
But somehow it does not work.
Currently I use an input boolean (as a switch in lovelace) and a timer to pause AdGuard for 30 minutes, and reactivate once the timer has reached zero:
But if possible I would of course put that in a single fance button card
So with your example of the timer inside the button card, I tried to start as simple as possible with my input boolean and the timer:
But somehow the timer thing does not work, while the button changes the input boolean as intended and the timer actually starts, the card stays with that object placeholder:
this doesnt happen often, but for the life of me I cant understand why a button shows an icon that isnt explicitly set, or is inherited from the domain or entity itself for that matter:
same happening on a switch, nb with device_class switch. showing the flash icon while the frontend should be showing toggle/off
@romrider, sorry for this silly question, but doesnt button card follow backend icon settings by default? Or has is just not adjusted to the new frontend pr that were merged lately
I’m trying to get the name and state of an entity horizontally aligned within this button. Unfortunately, layout: name_state doesn’t do what I want, since it just crams the two together:
I’m trying to color a button based on the state_attr of another entity… this stems from a conditional script I’m putting together to join/unjoin Sonos speakers to groups, and display different colors based on their group membership. Here’s what I have that doesn’t work for me so far:
type: custom:button-card
color_type: card
aspect_ratio: 2/1
color: auto
entity: media_player.sonos_living_room
name: Living Room
show_name: true
tap_action:
action: call-service
service: script.turn_on
service_data:
entity_id: script.sonos_living_room_join_unjoin_kitchen
show_state: false
state:
- color: |
[[[
if ('media_player.sonos_kitchen' in state_attr('media_player.sonos_living_room', 'sonos_group') return 'rgba(0,200,0,.7)';
else return 'rgba(200,200,0,.7)';
]]]
icon: mdi:speaker-wireless
value: playing
Unfortunately, it’s only returning my rgba(0,200,0,0.7). Where have I gone wrong here?
You’re right! And I edited my comment it just as you responded. I’m now getting one color, but not both.Nope… I was mistaken. My code is still worthless, let me try what you’ve suggested…
EDIT: No, unfortunately, that just gave me a blank white button in either case… still fooling with it.
type: custom:button-card
color_type: card
aspect_ratio: 2/1
color: auto
entity: media_player.sonos_living_room
name: Living Room
show_name: true
tap_action:
action: call-service
service: script.turn_on
service_data:
entity_id: script.sonos_living_room_join_unjoin_kitchen
show_state: false
state:
- color: >
[[[ if ("media_player.sonos_kitchen") in
(state_attr["media_player.sonos_living_room"], 'sonos_group') return
'blue';
else return 'rgba(200,200,0,.7)';
]]]
icon: mdi:speaker-wireless
value: playing
When I play sonos_living_room (state = playing) and it’s in no group, the button remains green and the icon changes from white to black. When I then add it to the group with sonos_kitchen, it does not change. Hm.
also, since the icon isnt state dependent (?) id set that in the button_config itself.
nope, none of these 3 will work, because they are not correct you need to set the color to the icon, which you dont do in either of the 3 examples. (the last 2 also have incorrect templates swill not work. there should be a . before attributes, and states['media_player.sonos_living_room.attributes.sonos_group'] simply isnt the way the state attributes are found.
Thank you–I’m making some progress, but I’m not there yet.
I have color_type set to card, and I’m actually trying to get the card color to change (the icon will stay white, or maybe change color on state only). For that reason–and because it’s where my entity states have been responsible for changing colors until now–I’ve been playing around in this section.
So, I used your code and replaced icon with card, and while I do get a color change, the card is black when playing; and black regardless of the value of sonos_group:
Had I seen orange and blue, I could claim success, but I’m not there yet. Thanks for looking at this and providing suggestions; any ideas to push me over the finish line?
Ah, right. Thanks. I first created this card a long time ago from copying & pasting examples, and I’ve learned a bit since then. This card and every similar one started this morning with - color , and now I’m remedying that.
I’ve been at this little problem for a few hours and I’m stuck. I frankly don’t get why icon: works and card: doesn’t. I can change the setting of color_type: but that royally screws up the card.
Well, those colors were relevant to the card (state) and it worked as I’d hoped, at least until my requirements changed earlier today. At this point I’m not sure how to accomplish the card-color-change based on sonos_group.
No, the order isn’t important, but putting the value of state first is more logical for me than color. In the original code, I wanted to change the card color and not the icon.
EDIT: The corrected code in your last post does something different from mine; mine may (?) be bad form, but the icon changes in form as intended, and the card changes in color as intended. Your corrected code changes the icon color instead of the card, and the card turns black instead of whatever color it was before. That’s not what I was looking to do when I put these buttons together sometime last year.
Ah well. I’m still playing with it and not finding any way to do it, so maybe it’s not possible with the button card.
EDIT: In the end… I accomplished what I wanted to do with a few template sensors and conditional cards. The button backgrounds change according to whether the speakers are grouped or not, playing or not, etc. As a bonus, I can call the join & unjoin services directly instead of using scripts. My only remaining gripe is that using conditional cards in this way–showing one button or the other, arranged in a horizontal stack–results in a slight horizontal offset; i.e., things don’t line up as nicely. Oh well.