Hi!
I don’t think this will work with an entity card! For me, this code only works in a template card. Here’s a link if you want to do it with Card Mod.
type: custom:mushroom-legacy-template-card
entity: switch.all_switch
primary: Test
secondary: etc
icon: mdi:light-switch
icon_color: |2-
{% if is_state('switch.all_switch', 'on') %}
red
{% else %}
green
{% endif %}
layout: horizontal