Sorry this might be easy, but I really struggle with (what feels at least) really odd syntax variations - as an aside if anyone can recommend some good guides to the vaguaries of using HA templating / Jinja2 that would be great.
My current challange is I am trying to make a situation where the styling (specifically background-color) fon a card is dependant on whether or not a particular entity_id is part of a group.
I have seen and successfully used something which changes the background-color to the rgb value if a light is switched on, using the following:
type: custom:config-template-card
entities:
- light.study_lights_group
- group.dynamic_lights
card:
type: picture-elements
image: local/floorplan_ground2.png
elements:
- type: image
image: /local/study.png
style:
background-color: >-
${var light_rgb='252, 3, 140'; if
(states['light.study_bl'].state == 'on') 'rgba('+light_rgb+',1)';
else 'rgba(0,0,0,0)';}
top: 35.45%
left: 77.85%
width: 23.1%
transform: rotate(-90deg)
entity: light.study_lights_group
tap_action:
action: call-service
service: script.group_change
service_data:
selected_light: light.study_lights_group
but I cannot work out how to incorporate this with the template approach for checking if a string is “in” an attribute. i.e. this resolves correctly in developer mode:
{% if "light.study_lights_group" in state_attr("group.dynamic_lights","entity_id") %}
but I don’t understand how to lift and shift that into my card. For example this doesn’t work:
- type: image
image: /local/study.png
style:
background-color: >-
${var light_rgb='252, 3, 140'; if
"light.study_lights_group" in state_attr("group.dynamic_lights","entity_id")
'rgba('+light_rgb+',1)'; else 'rgba(0,0,0,0)';}
top: 35.45%
left: 77.85%
width: 23.1%
transform: rotate(-90deg)
entity: light.study_lights_group
tap_action:
action: call-service
service: script.group_change
service_data:
selected_light: light.study_lights_group
Or if I simply further …
card:
type: picture-elements
image: local/floorplan_ground2.png
elements:
- type: image
image: /local/study.png
style:
background-color: >-
${if ("light.study_lights_group" in
state_attr("group.dynamic_lights","entity_id") == 'True') 'rgba(252,
3, 240, 1)'; else 'rgba(0,0,0,0)';}
top: 35.45%
left: 77.85%
width: 23.1%
transform: rotate(-90deg)
entity: light.study_lights_group
tap_action:
action: call-service
service: script.group_change
service_data:
selected_light: light.study_lights_group
I have tried a variety of options for ’ " and { but since I am just shooting in the dark and nothing worked I am appeallng to the hive mind for guidance!
Thoughts appreciated
S