You basically don’t change anything "on the Sensor) you change it in the Card where you present the Sensors.
There are dedicated cards for “battery level card” , but if you already have your “design” in place and just want to change the color’s as mentioned, you can either use “template” or “card_mod”
So what you should do, is “present” show your view/card, so people can SEE what/where you want to change, if you have made any attempt to change the colors on specific Card/Entity, the even show your code.
im sure you have seen above “requirements” in the examples" you mention, else SEARCH for the excact same phrase as you have in your Header " icon color based on state/value" or similar i.e “card_mod” “battery state card”
PS: MQTT has nothing to do with your Dashboard/Card Design