Custom sensor icon in mushroom entity / dashboard

I just managed to make my ESPresence to work and I am tracking my device called “avPhone”. I have customized the icon for it in my customize.yaml

sensor.avPhone:
  icon: mdi:cellphone

The result is here:

I want the icon of my smart band to change its icon depends on where I am (in which room), so I used this code in customize.yaml but does not do anything. It shows empty icon:

sensor.alex_room:
  icon: >
    if (state === 'office') return 'mdi:desktop-classic';
    else if (state === 'bedroom') return 'mdi:bed';
    else if (state === 'livingroom') return 'mdi:sofa';
    else if (state === 'diningroom') return 'mdi:table-furniture';
    else if (state === 'kitchen') return 'mdi:toaster-oven';
    else return 'mdi:cellphone';

Am I doing it wrong, how can I change mushroom card entity card icon based on state. I want to be able to use this in my dashboard, and see which person is in which room:

You cannot use templates in customize.yaml. Either, create a template sensor which sets the icon and use that in your card, or use a mushroom template card.

How to create template sensor which sets the icon?

HEre is the code I stole from REED SMART HOME for my sensor: that switches to my BOSE headphones when my phone is charing:

- platform: template
  sensors:
    alex_room:
      friendly_name: "Alex room"
      value_template: >
        {% if is_state("sensor.alexphone_battery_state", "charging") and (states.sensor.avPhone.state != "not_home") -%}
          {{(states.sensor.Bose.state)}}
        {%- else -%}
          {{(states.sensor.avPhone.state)}}
        {%- endif %}

How do I amend sensor icons here?

- platform: template
  sensors:
    alex_room:
      friendly_name: "Alex room"
      value_template: >
        {% if is_state("sensor.alexphone_battery_state", "charging") and (states.sensor.avPhone.state != "not_home") -%}
          {{(states.sensor.Bose.state)}}
        {%- else -%}
          {{(states.sensor.avPhone.state)}}
        {%- endif %}
      icon: >
          {% if is_state("sensor.alexphone_battery_state", "charging") %}
            mdi:battery-charging
          {% else %}
            mdi:battery
          {% endif %}

Or whatever icons/entity state you want to use.

Template docs are here with good examples.

It does not work: IT says: Property icon is not allowed.

Ok try with new format template sensors

template:
  - sensor:
      name: "Alex room"
      value_template: >
        {% if is_state("sensor.alexphone_battery_state", "charging") and (states.sensor.avPhone.state != "not_home") -%}
         {{(states.sensor.Bose.state)}}
        {%- else -%}
         {{(states.sensor.avPhone.state)}}
        {%- endif %}
      icon: >
        {% if is_state("sensor.alexphone_battery_state", "charging") %}
          mdi:battery-charging
        {% else %}
          mdi:battery
        {% endif %}

That is in sensors.yaml


That in cofiguration.yaml

tried both, copy/paste the code from you but no luck