I intend to repeat this configuration all over the floor plan, so I’m looking for a a more efficient way to write the yaml.
If you look at the style
under card_mod
, I use a condition to choose the icon that I need to display depending upon the state of the entity.
If I were to repeat this for every icon, I might find myself writing this code over and over again.
In the templated section, is there a way to refer to the state-icon’s entity for the value in the condition?
- type: state-icon
entity: binary_sensor.amcrest_patio_motion_detected
card_mod:
style: |
:host {
{% if is_state('binary_sensor.amcrest_patio_motion_detected','off') %}
--card-mod-icon: mdi:cctv;
{% else %}
--card-mod-icon: mdi:ab-testing;
{% endif %}
}
The only thing I though of was to set a variable value to binary_sensor.amcrest_patio_motion_detected
and then reference that value in the template, but I can’t figure out if that will work, nor what the proper syntax would be.
Example:
- type: state-icon
entity:
value_template: >
{% set entity = binary_sensor.amcrest_patio_motion_detected %}
{{entity}}
card_mod:
style: |
:host {
{% if is_state('{{entity}}','off') %}
--card-mod-icon: mdi:cctv;
{% else %}
--card-mod-icon: mdi:ab-testing;
{% endif %}
}
Wondering if there’s a different approach or if I’m on the right track?