Well, you set a color of this heading’s badge in Config - and now wish to change this color dynamically dependently on some entity, right?
Your possible way is using card-mod: colorize an icon dependently on some entity.
Go to the main card-mod thread (cannot give a link) - go to the 1st post - find a link at the bottom titled “fantastic post” - scroll down to a “Heading card” chapter in that post.
Suggest to ask all card-mod related questions in that thread.