Template Binary Sensor - Need status to change icon color

I have seen this question asked before, but can’t seem to find a definitive answer. I have a Template Binary Sensor to check if my WAN connection is up or down, and another to check firewall status. I want to make the icon turn green if WAN is “Up” or firewall is “Online”, and red if WAN is “Down” or firewall is “Disabled”. Does anyone know how to accomplish this? Thanks in advance!

In config.yaml:

binary_sensor:

  • platform: ping
    name: wan_status
    host: google.com
    scan_interval: 10

  • platform: ping
    name: firewall_status
    host: mail.ru
    scan_interval: 10

In sensors.yaml:

  • platform: template
    sensors:
    wan_status:
    friendly_name: WAN Status
    entity_id:
    - binary_sensor.wan_status
    value_template: >-
    {%- if is_state(“binary_sensor.wan_status”, “on”) -%}
    Up
    {%- else -%}
    Down
    {%- endif -%}

  • platform: template
    sensors:
    firewall_status:
    friendly_name: Firewall Status
    entity_id:
    - binary_sensor.firewall_status
    value_template: >-
    {%- if is_state(“binary_sensor.firewall_status”, “on”) -%}
    Offline
    {%- else -%}
    Online
    {%- endif -%}

In customize.yaml:

sensor.wan_status:
icon: mdi:wan

sensor.firewall_status:
icon: mdi:security-network