I’ve just converted all my custom buttons from using templates to using the quite brilliant lovelace-gen as I thought that would give me more flexibilty. And in some ways it does.
But there is a big drawback in that you can’t pass any states into the button whereas in templates you can access them in the template itself.
It wasn’t a big task to change them so it’s not a big deal to change them back but before I do I just wondered what the panel thought?
I just switched to lovelace gen. I have no idea what limitation you are talking about. I don’t see any limitations like that. Can you elaborate more, I’d bet there’s a solution.
EDIT: Just to say, I made a button card last night that you can feed it a state, domain, icon, group, and group name. It will count the items at that state and display it in the upper right corner. All using a lovelace button card template and lovelace-gen.
EDIT: gotta work on the state color of the main icon… never noticed that. Always something to do…
EDIT: Well not exactly an edit as I haven’t posted it yet but I typed in all that comes below and realised my dilemma is not really between lovelace-gen and templates at all. I think that if I use both that might be a solution. If you can bear to follow my ramblings below I’d be interested if you have a way to do this.
Hang on…
Are you using all three? custom-button-card based on a template and lovelace-gen?
One specific thing I want to do is…
I have a set of zones, and each one for example has an input_number of the format input_number.zone_X
I’d like to be able to define the name they appear with in the UI dynamically so each one also has an input_text in the form input_text.zone_X_name
My button needs to be based on the input_number but I want the text shown to be the input_text
There are 8 zones (and three cycles so actually 24 zones) so instead of repeating the Lovelace code 8 (24) times I do it using includes. I can’t find a way to pass the state of the input_text into the button using lovelace-gen
I hope this is making sense… maybe a picture will help. (This is currently based on actual entities rather than buttons but the principle still holds - I think)
Ah, I see. Use the template card provided by @iantrich. It will work with this. It’s a js template card instead of jinja so it shouldn’t get confused with @thomasloven’s lovelace-gen functionality.
I haven’t done this yet but I will be in the next few days during my move towards lovelace-gen. Anyways, this is what it would generally look like.
#==============================================================
#=== A line for each zone showing duration and skip check-box
#==============================================================
type: custom:mod-card
style: |
ha-card {
border: 1px solid var(--primary-background-color);
}
card:
type: custom:hui-horizontal-stack-card
cards:
- type: custom:config-template-card
variables:
- states['input_text.irrigation_zone{{ zone }}_name'].state
entities:
- input_text.irrigation_zone{{ zone }}_name
card:
type: entities
show_header_toggle: false
entities:
- entity: input_number.irrigation_cycle{{ cycle }}_zone{{ zone }}_duration
name: "${ var[0] }"
... etc ....
EDIT: I forgot that I don’t need to terminate or use the word return in single line templates for that card.
One more quick question on this. The three big cycle buttons across the top act as radio buttons i.e. only one should be on at the same time, and they control what is displayed below. Simple automations ensure only one is on at a time but I need the tap action to be none when the button is on else if it is toggled whilst on then all the buttons would be off messing up the whole ui.
To make the template generic so it can also be used as a non-radio select button I want to pass it a parameter to indicate this behaviour is required:
It ‘works’, albeit without the flexibility of having that behaviour optional.
(And yes, I use that template elsewhere for buttons that are not ‘radio buttons’ so I’d really like it!)
Is this your own card? Or is this something available? It looks really good, I’m not sure I would trust HA to run my sprinkler system (what if it crashes while a zone is on?) but I do have it linked to my rachio account so that I can mess with the zones, which worked well for when I installed sod last year.
That card is a piece meal card. He’s using a series of cards to configure that. It’s not a single custom card that you can install, if that’s what you’re asking.
As for letting HA run your irrigation, I have been doing it for two years (summers only ) with no problem. In fact it is probably why I found HA, and stayed.
Search for garden irrigation on here and you’ll find plenty of people doing it. You might even find my effort which I’m currently re doing. Hence the new UI.