with_state_indicator:
  variables:
    state_indicator_id:  # defaults to entity_id

    state_indicator_size: 2px
    state_indicator_off_size:  # If set, used when the state_indicator entity is off

    # state indicators are used when the entity's state is not 'on'
    state_indicator_on_color: white
    state_indicator_off_color: transparent

    # state_on_indicator_s are used when the entity's state is 'on':
    state_on_indicator_on_color: white
    state_on_indicator_off_color: transparent

  triggers_update: all  # unfortunately a template doesn't seem to work here :/
  double_tap_action:
    action: call-service
    service: homeassistant.toggle
    service_data:
      entity_id: "[[[ return variables.state_indicator_id || entity.entity_id ]]]"
  styles:
    name:
      - transform: >
          [[[
            const state_indicator_entity = variables.state_indicator_id || entity.entity_id;

            const size = states[state_indicator_entity].state === 'on'
              ? variables.state_indicator_size
              : variables.state_indicator_off_size || variables.state_indicator_size

            return 'translateY(' + size + ')'
          ]]]

    card:
      - border-bottom: >-
          [[[
            let color;
            const state_indicator_entity = variables.state_indicator_id || entity.entity_id;
            const is_state_indicator_on = Boolean(states[state_indicator_entity].state === 'on');

            if (entity.state === 'on') {
              color = is_state_indicator_on
                  ? variables.state_on_indicator_on_color
                  : variables.state_on_indicator_off_color;
            } else {
              color = is_state_indicator_on
                  ? variables.state_indicator_on_color
                  : variables.state_indicator_off_color;
            }

            const size = is_state_indicator_on
              ? variables.state_indicator_size
              : variables.state_indicator_off_size || variables.state_indicator_size

            return size + ' solid ' + color;
          ]]]
