The below is the code for one of my buttons for my person card, I'm using variables to make it easy to duplicate for other users. The issue I'm struggling with is referencing the variable in the if statement, it works fine as written below, but I would like to only have to update sensors once, rather than trawling through code to find the one I usually miss. Is it possible to reference the variables in the if statements?
I've accomplished what you're trying to do by using one of two different methods depending on what my needs are.
Method One: Button Card Template
I use this method for every custom:button-card on my dashboard. It allows the user to create templates that define a specific set of parameters and then apply those templates to individual button cards based on their purpose. This avoids having to redefine the same parameters for multiple similar cards.
Below is an example of how I use this approach. The first section is applied directly to my dashboard and creates a custom button card that references two different templates. The second section contains the actual template definitions, which are added after the title: line in the “Raw configuration editor” of the dashboard. You can access this editor by clicking the three dots in the top-right corner while in editing mode.
The first template defines the default style that I use for most of the custom button cards on my dashboard. The second template defines a style used specifically for the OFF buttons on my dashboard and is only applied when certain conditions are met. This template also enables the tap action function, which is used to trigger a script that turns off the light.
You may notice that the second template includes some of the same style settings as the first template. This is intentional. Templates are applied in the order they are referenced in the card, meaning the settings from the template listed last will override any conflicting settings from templates listed before it.
Since Method One only applies to the custom:button-card, I use this method for other card types or when working with multiple cards. This approach allows the user to create templates that define entire cards, not just individual parameters like the button card template method.
Below is an example of how I use it. The first section is applied directly to a grid card on my dashboard. For each card in the grid, I reference the same decluttering card template but define the variables differently based on each card’s purpose. The second section contains the actual decluttering card template definition, which is added after the title: line in the “Raw configuration editor” of the dashboard, just like the button card template section.
If you are using both methods, place the decluttering card template section first and the button card template section after it.