Template icon based on state... without duplicating the logic

When defining a template sensor in which you want to dynamically set the icon, is there anyway to do this directly from the sensors state… or do you have to duplicate the logic essnetially?

An example below:

- name: "Announcements Permissive"
    unique_id: announcements_permissive
    icon: >-
      {% if is_state('binary_sensor.sleep_mode', 'off') and is_state('input_boolean.force_disable_announcements', 'off') %}
        mdi:volume-high
      {% else %}
        mdi:volume-off
      {% endif %}
    state: >-
      {{ is_state('binary_sensor.sleep_mode', 'off') and is_state('input_boolean.force_disable_announcements', 'off') }}

Can I not just do something like this:

- name: "Announcements Permissive"
    unique_id: announcements_permissive
    icon: >-
      {% if my_state('on') %}
        mdi:volume-high
      {% else %}
        mdi:volume-off
      {% endif %}
    state: >-
      {{ is_state('binary_sensor.sleep_mode', 'off') and is_state('input_boolean.force_disable_announcements', 'off') }}

I’ve found some similar posts on template icons and states such as this and this but couldn’t find anyone asking this seemingly logical next question.

if this.state == 'on'

Thank you!