What conditional element do you mean, show a code with a conditional element with a failed attempt to use card-mod.
Anyway, check possible solutions (and a related glitch as well) for styling a conditional element in picture-elements: go to huge card-mod thread → 1st post → link at the bottom → styles for picture-elements.
Do you have a “width” properly scaled on different viewports?
It works with card mod- it doesn’t work if I used the picure-element conditional (at least not consistently), but only for boolean helpers, using conditional for things like switches work fine.
You are using card-mod for styling a conditional element in a wrong way. Check the link I gave earlier (card-mod thread → …).
Strongly suggest you to not use card-mod to style an element if it may be done by a native “style” option.
The latter point:
Assume you need to style some sub-element inside an element (for instance, a background of “span” UoM part of “state-badge”). It may be only done by card-mod.
Assume you need to colorize a “state-label” dynamically. Set a “color” property inside a native “style” option to some CSS variable - which is set by card-mod (i.e. card-mod is only used to set a variable).
Assume you need to define an animation for some element. It may be only done by card-mod.
Also:
4. Assume you need to mass-style many elements: all “state-badge” elements must have a red background. Then use card-mod to define a corr. CSS variable on a card’s level - then elements will use this changed variable automatically.
5. If you need to style many elements similarly (if it cannot be achieved in pt. 4) - it may be done either on an element’s level by using yaml-anchors for repeating code (see pts. 1,3 above) or it may be done on a card’s level (need to define DOM paths to each element; a bit cumbersome; could be unstable).
Picture Elements, multiple state images, (on, off, “partial-on”)
I’ve been playing around with picture elements and I could get the ON and OFF states to load specific images, I’m curious to know if it’s possible to load a third state for a light group if: “not all of them are ON”
So if a light group has 3 lights:
State ON = all 3 lights ON
State OFF = all 3 lights OFF
State “partial-on” ( not sure what to call this yet) = 1 or 2 lights are ON
here is an example of what I currently have, these are group lights (all on)
this is what they look like when they are all off:
I’ve been toying with the idea of creating a third state when only some of the lights are ON/OFF in a group, then it would load another type of image, and that state would be like this:
(not sure when yet what I want to call this state yet, something more logical than “partially-on”)
here’s my current code for ON / OFF that’s working fine for me, example is the Upstairs light group.
is there an easy way to write a new undefined state for any light group that only some of the lights are on/off? this whole templating code in homeassistant is way over my head and can’t quite grasp how to create it
So I was able to finally make this happen, but it required a whole bunch of modifications. I basically got a sensor template recommended by chatGPT and downloaded browsermod plugin to customize the hold action. Also added some animations.
I should have done a little more research before I posted. I just found that out and was on my way back to edit my post but you had already commented. Thanks though.
For experienced users who deal with card-mod for some time, a necessity to add the “card_mod” keyword is obvious.
Earlier a card-mod code usually worked w/o that “card_mod” keyword (it was only crucial for styling elements inside picture-elements card). But adding the “card_mod” keyword was recommended as a “good practice” for future compatibility.
That is why in Community (like this dedicated card-mod thread) people may find plenty of card-mod examples w/o this “card_mod” keyword; many of these examples may still work with added “card_mod” keyword (with a proper indentation).
I would like to embed cards saved in yaml, but I don’t understand how to insert the style properties to position it, and maybe also some css via card_mod.
that’s what I thought but it doesn’t work.